Java 1.1 | appendable closeable flushable | This class is a character output stream that uses an internal character array as the destination of characters written to it. When you create a CharArrayWriter , you may optionally specify an initial size for the character array, but you do not specify the character array itself; this array is managed internally by the CharArrayWriter and grows as necessary to accommodate all the characters written to it. The toString( ) and toCharArray( ) methods return a copy of all characters written to the stream, as a string and an array of characters, respectively. CharArrayWriter defines the standard write( ) , flush( ) , and close( ) methods all Writer subclasses define. It also defines a few other useful methods. size( ) returns the number of characters that have been written to the stream. reset( ) resets the stream to its initial state, with an empty character array; this is more efficient than creating a new CharArrayWriter . Finally, writeTo( ) writes the contents of the internal character array to some other specified character stream. CharArrayWriter is the character-stream analog of ByteArrayOutputStream and is quite similar to StringWriter . Figure 9-8. java.io.CharArrayWriter public class CharArrayWriter extends Writer { // Public Constructors public CharArrayWriter ( ); public CharArrayWriter (int initialSize ); // Public Instance Methods 5.0 public CharArrayWriter append (CharSequence csq ); 5.0 public CharArrayWriter append (char c ); 5.0 public CharArrayWriter append (CharSequence csq , int start , int end ); public void reset ( ); public int size ( ); public char[ ] toCharArray ( ); public void writeTo (Writer out ) throws IOException; // Public Methods Overriding Writer public void close ( ); empty public void flush ( ); empty public void write (int c ); public void write (char[ ] c , int off , int len ); public void write (String str , int off , int len ); // Public Methods Overriding Object public String toString ( ); // Protected Instance Fields protected char[ ] buf ; protected int count ; } |