The class implements a character buffer that can be used as an Writer.The buffer automatically grows when data is written to the stream.

Class declaration

Following is the declaration for class:

public class CharArrayWriter
   extends Writer


Following are the fields for class:

  • protected char[] buf -- This is the buffer where data is stored.

  • protected int count -- This is the number of chars in the buffer.

  • protected Object lock -- This is the object used to synchronize operations on this stream.

Class constructors

S.N.Constructor & Description
1 CharArrayWriter()
This creates a CharArrayReader from the specified array of chars.
2 CharArrayWriter(int initialSize)
This creates a new CharArrayWriter with the specified initial size.

Class methods

S.N.Method & Description
1 CharArrayWriter append(char c)
This method appends the specified character to this writer.
2 CharArrayWriter append(CharSequence csq)
This method appends the specified character sequence to this writer.
3 CharArrayWriter append(CharSequence csq, int start, int end)
This method appends a subsequence of the specified character sequence to this writer.
4 void close()
This method close the stream.
5 void flush()
This method flush the stream.
6 void reset()
This method resets the buffer so that you can use it again without throwing away the already allocated buffer.
7 int size()
This method returns the current size of the buffer.
8 char[] toCharArray()
This method returns a copy of the input data.
9 String toString()
This method converts input data to a string.
10 void write(char[] c, int off, int len)
This method writes characters to the buffer.
11 void write(int c)
This method writes a character to the buffer.
12 void write(String str, int off, int len)
This method write a portion of a string to the buffer.
13 void writeTo(Writer out)
This method writes the contents of the buffer to another character stream.

Methods inherited

This class inherits methods from the following classes: