java.io.CharArrayWriter
java.io.Writer
None
None
New as of JDK 1.1
The CharArrayWriter class represents a stream whose data is written to an internal character array. This class is similar to ByteArrayOutputStream, but it operates on an array of Java characters instead of a byte array.
The data from a CharArrayWriter can be sent to another Writer using the writeTo() method. A copy of the array can be obtained using the toCharArray() method.
public class java.io.CharArrayWriter extends java.io.Writer { // Variables protected char[] buf; protected int count; // Constructors public CharArrayWriter(); public CharArrayWriter(int initialSize); // Instance Methods public void close(); public void flush(); public void reset(); public int size(); public char[] toCharArray(); public String toString(); public void write(int c); public void write(char[] c, int off, int len); public void write(String str, int off, int len); public void writeTo(Writer out); }
The buffer that holds data for this stream.
A placeholder that marks the end of the data in the buffer.
This constructor creates a CharArrayWriter with an internal buffer that has a default size of 32 characters. The buffer grows automatically as data is written to the stream.
The initial buffer size.
This constructor creates a CharArrayWriter with an internal buffer that has a size of initialSize characters. The buffer grows automatically as data is written to the stream.
Writer.close()
This method does nothing. For most subclasses of Writer, this method releases any system resources that are associated with the Writer object. However, the CharArrayWriter's internal array may be needed for subsequent calls to toCharArray() or writeTo(). For this reason, close() does nothing, and the internal array is not released until the CharArrayWriter is garbage collected.
Writer.flush()
This method does nothing. The CharArrayWriter writes data directly into its internal array; thus it is never necessary to flush the stream.
This method discards the current contents of the buffer and resets the position of the stream to zero. Subsequent data is written starting at the beginning of the array.
This method returns the number of characters currently stored in this object's internal buffer. It is a count of the number of characters that have been written to the stream.
A copy of the data that has been written to this CharArrayWriter in the form of a char array.
This method copies the data in the internal array and returns a reference to the copy. The returned array is as long as the data that has been written to the stream, i.e., the same as size().
A copy of the data that has been written to this CharArrayWriter in the form of a String.
Object.toString()
This method returns a reference to a String object created from the characters stored in this object's internal buffer.
The value to write.
Writer.write(int)
This method writes the low-order 16 bits of the given value into the internal array. If the array is full, a larger array is allocated.
An array of characters to write to the stream.
An offset into the character array.
The number of characters to write.
Writer.write(char[], int, int)
This method copies len characters to this object's internal array from c, starting off elements from the beginning of the array. If the internal array is full, a larger array is allocated.
A String to write to the stream.
An offset into the string.
The number of characters to write.
Writer.write(String, int, int)
This method copies len characters to this object's internal array from str, starting off characters from the beginning of the given string. If the internal array is full, a larger array is allocated.
The destination stream.
If any kind of I/O error occurs.
This method writes the contents of this object's internal buffer to the given Writer. All the data that has been written to this CharArrayWriter is written to out.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
equals(Object) |
Object |
finalize() |
Object |
getClass() |
Object |
hashCode() |
Object |
notify() |
Object |
notifyAll() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
write(char[]) |
Writer |
write(String) |
Writer |
IOException, String, Writer
This HTML Help has been published using the chm2web software. |