java.io.CharArrayWriter (JDK 1.1)
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, either as a string or as an array of characters.
CharArrayWriter defines the standard write(), flush(), and close() methods that all Writer subclasses do. 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.
public classCharArrayWriterextends Writer { //Public ConstructorspublicCharArrayWriter(); publicCharArrayWriter(intinitialSize); //Protected Instance Variablesprotected char[]buf; protected intcount; //Public Instance Methodspublic voidclose(); //Defines Writerpublic voidflush(); //Defines Writerpublic voidreset(); public intsize(); public char[]toCharArray(); public StringtoString(); //Overrides Objectpublic voidwrite(intc); //Overrides Writerpublic voidwrite(char[]c, intoff, intlen); //Defines Writerpublic voidwrite(Stringstr, intoff, intlen); //Overrides Writerpublic voidwriteTo(Writerout) throws IOException; }
Hierarchy:
Object->Writer->CharArrayWriter