com.ccg.macros
Class OutputNull

java.lang.Object
  extended by com.ccg.macros.OutputNull
All Implemented Interfaces:
Output

public final class OutputNull
extends Object
implements Output

A "null" output device for interpreter output.

At times it is useful to disable output while interpretting data. If you pass one of these objects to a Interpreter, then any normal output generated will be discarded.

This can be particularily useful when "loading" an interpreter with some default rules.

For example, suppose you wanted to load definitions from a file into a AtMacros object without producing any output. You could do this with a method like this:

 public static void loadDefinitions(AtMacros amacs, File src) 
   throws IOException, InterpretException {

   Input in = new InputReader(src);
   amacs.interpret(in,new {@link OutputNull OutputNull}());
 
 
 

Since:
1.0
Version:
$Revision: 1.1.1.1 $
Author:
$Author: pkb $
See Also:
AtMacros

Constructor Summary
OutputNull()
           
 
Method Summary
static Output getInstance()
          Reference to the single global null output device.
 void write(char[] buf, int ofs, int len)
          Writes a set of characters from a buffer to the output.
 void write(Object o)
          Outputs the string representation of a Object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OutputNull

public OutputNull()
Method Detail

write

public void write(char[] buf,
                  int ofs,
                  int len)
           throws IOException
Writes a set of characters from a buffer to the output.

This method is used by macro processors (such as the AtMacros class) to send a set of characters to the output device (string, file, etc). However, since this is a "null" writer - no output is never done.

Specified by:
write in interface Output
Parameters:
buf - A character array to take the data from (must not be null)
ofs - Offset into the buffer to the first character to start the copy from. Should be in the range of [0,buf.length-1].
len - How many characters to copy. When added to the offset, the resulting value should not exceed the length of the array.
Throws:
IOException - If a I/O error is encountered (never thrown since we don't do anything).
Since:
1.0

write

public void write(Object o)
           throws IOException
Outputs the string representation of a Object.

This method is used by macro processors (such as the AtMacros class) to cause the string representation of a Object to be sent to the output device. However, since this is a "null" writer - no output is never done.

Specified by:
write in interface Output
Parameters:
object - The object to write out (the toString() method is used to write out the string representation of the object). You may pass null (in which case nothing will be done).
Throws:
IOException - If a I/O error is encountered (never thrown since we don't do anything). y *
Since:
1.0

getInstance

public static Output getInstance()
Reference to the single global null output device.

Since this object doesn't do anything, a single instance can be used throughout the JVM. Use this method to get access to it (this avoid constructing new intances).

Returns:
Non-null reference to the single global instance of the null output device.
Since:
1.0


Copyright 1998-1998-2006 null. All Rights Reserved.