| java.lang.Object | ||
| ↳ | java.io.Writer | |
| ↳ | java.io.CharArrayWriter | |
A specialized Writer for class for writing content to an (internal) char array. As bytes are written to this writer, the char array may be expanded to hold more characters. When the writing is considered to be finished, a copy of the char array can be requested from the class.
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|  | buf | The buffer for characters. | |||||||||
|  | count | The ending index of the buffer. | |||||||||
| [Expand] 
           Inherited Fields
           | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|  From class java.io.Writer | |||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|  | 
           Constructs a new 
            CharArrayWriterwhich has a buffer allocated with the default size of 32 characters. | ||||||||||
|  | 
           Constructs a new 
            CharArrayWriterwhich has a buffer allocated with the size ofinitialSizecharacters. | ||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|  | 
           Append a subsequence of a 
            CharSequenceto theCharArrayWriter. | ||||||||||
|  | 
           Appends a char 
            cto theCharArrayWriter. | ||||||||||
|  | 
           Appends a 
            CharSequenceto theCharArrayWriter. | ||||||||||
|  | 
           Closes this writer.
           | ||||||||||
|  | 
           Flushes this writer.
           | ||||||||||
|  | 
           Resets this writer.
           | ||||||||||
|  | 
           Returns the size of this writer, that is the number of characters it stores.
           | ||||||||||
|  | 
           Returns the contents of the receiver as a char array.
           | ||||||||||
|  | 
           Returns the contents of this 
            CharArrayWriteras a string. | ||||||||||
|  | 
           Writes 
            countcharacters starting atoffsetincto this writer. | ||||||||||
|  | 
           Writes the specified character 
            oneCharto this writer. | ||||||||||
|  | 
           Writes 
            countcharacters starting atoffsetfrom the stringstrto this CharArrayWriter. | ||||||||||
|  | 
           Writes the contents of this 
            CharArrayWriterto anotherWriter. | ||||||||||
| [Expand] 
           Inherited Methods
           | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|  From class java.io.Writer | |||||||||||
|  From class java.lang.Object | |||||||||||
|  From interface java.io.Closeable | |||||||||||
|  From interface java.io.Flushable | |||||||||||
|  From interface java.lang.Appendable | |||||||||||
Constructs a new CharArrayWriter which has a buffer allocated with the default size of 32 characters. This buffer is also used as the lock to synchronize access to this writer. 
Constructs a new CharArrayWriter which has a buffer allocated with the size of initialSize characters. The buffer is also used as the lock to synchronize access to this writer.
| initialSize | the initial size of this CharArrayWriters buffer. | 
|---|
| IllegalArgumentException | if initialSize < 0. | 
|---|
Append a subsequence of a CharSequence to the CharArrayWriter. The first and last characters of the subsequence are specified by the parameters start and end. A call to CharArrayWriter.append(csq) works the same way as CharArrayWriter.write(csq.subSequence(start, end).toString). If csq is null, then it will be substituted with the string "null".
| csq | the CharSequenceappended to theCharArrayWriter, may benull. | 
|---|---|
| start | the index of the first character in the CharSequenceappended to theCharArrayWriter. | 
| end | the index of the character after the last one in the CharSequenceappended to theCharArrayWriter. | 
| IndexOutOfBoundsException | if start < 0,end < 0,start > end, or ifendis greater than the length ofcsq. | 
|---|
Appends a char c to the CharArrayWriter. The method works the same way as write(c).
| c | the character appended to the CharArrayWriter. | 
|---|
Appends a CharSequence to the CharArrayWriter. The method works the same way as write(csq.toString()). If csq is null, then it will be substituted with the string "null".
| csq | the CharSequenceappended to theCharArrayWriter, may benull. | 
|---|
Closes this writer. The implementation in CharArrayWriter does nothing. 
Flushes this writer. The implementation in CharArrayWriter does nothing. 
Resets this writer. The current write position is reset to the beginning of the buffer. All written characters are lost and the size of this writer is set to 0.
Returns the size of this writer, that is the number of characters it stores. This number changes if this writer is reset or when more characters are written to it.
Returns the contents of the receiver as a char array. The array returned is a copy and any modifications made to this writer after calling this method are not reflected in the result.
Returns the contents of this CharArrayWriter as a string. The string returned is a copy and any modifications made to this writer after calling this method are not reflected in the result.
Writes count characters starting at offset in c to this writer.
| buffer | the non-null array containing characters to write. | 
|---|---|
| offset | the index of the first character in bufto write. | 
| len | maximum number of characters to write. | 
| IndexOutOfBoundsException | if offset < 0orlen < 0, or ifoffset + lenis bigger than the size ofc. | 
|---|
Writes the specified character oneChar to this writer. This implementation writes the two low order bytes of the integer oneChar to the buffer.
| oneChar | the character to write. | 
|---|
Writes count characters starting at offset from the string str to this CharArrayWriter.
| str | the non-null string containing the characters to write. | 
|---|---|
| offset | the index of the first character in strto write. | 
| count | the number of characters from strto write. | 
| NullPointerException | if strisnull. | 
|---|---|
| StringIndexOutOfBoundsException | if offset < 0orcount < 0, or ifoffset + countis bigger than the length ofstr. | 
Writes the contents of this CharArrayWriter to another Writer. The output is all the characters that have been written to the receiver since the last reset or since it was created.
| out | the non-null Writeron which to write the contents. | 
|---|
| NullPointerException | if outisnull. | 
|---|---|
| IOException | if an error occurs attempting to write out the contents. |