java.io.StringWriter
java.io.Writer
None
None
New as of JDK 1.1
The StringWriter class represents a stream whose data is written to a string. This class is similar to the CharArrayWriter class, which writes its data to a char array. The StringWriter class uses a StringBuffer to store its data; a String can be retrieved with the toString() method.
public class java.io.StringWriter extends java.io.Writer { // Constructors public StringWriter(); protected StringWriter(int initialSize); // Instance Methods public void close(); public void flush(); public StringBuffer getBuffer(); public String toString(); public void write(int c); public void write(char[] cbuf, int off, int len); public void write(String str); public void write(String str, int off, int len); }
This constructor creates a StringWriter with an internal buffer that has a default size of 16 characters. The buffer grows automatically as data is written to the stream.
The initial buffer size.
This constructor creates a StringWriter 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 subclassesof Writer, this method releases any system resources that are associated with the Writer object. However, the StringWriter's internal buffer may be needed for subsequent calls to toString(). For this reason, close() does nothing, and the internal buffer is not released until the StringWriter is garbage collected.
Writer.flush()
This method does nothing. The StringWriter writes data directly into its internal buffer; thus it is never necessary to flush the stream.
A reference to the internal data buffer.
This method returns a reference to the StringBuffer object that is used in this StringWriter.
A String constructed from the internal data buffer.
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 given value into the internal buffer. If the buffer is full, it is expanded.
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 buffer from cbuf, starting off elements from the beginning of the array. If the internal buffer is full, it is expanded.
A String to write to the stream.
Writer.write(String)
This method copies the characters of str into this object's internal buffer. If the internal buffer is full, it is expanded.
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 buffer from str, starting off characters from the beginning of the given string. If the internal buffer is full, it is expanded.
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 |
CharArrayWriter, String, StringBuffer, Writer