Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.io

Class StringWriter

java.lang.Object
|
+--java.io.Writer
   |
   +--java.io.StringWriter


public class StringWriter

extends Writer

This class writes chars to an internal StringBuffer that can then be used to retrieve a String.

Authors:

Constructor Summary

StringWriter()

This method initializes a new StringWriter to write to a StringBuffer initially sized to a default size of 16 chars.
StringWriter(int size)

This method initializes a new StringWriter to write to a StringBuffer with the specified initial size.

Method Summary

voidclose()

This method closes the stream.
voidflush()

This method flushes any buffered characters to the underlying output.
java.lang.StringBuffergetBuffer()

This method returns the StringBuffer object that this object is writing to.
java.lang.StringtoString()

This method returns the contents of the internal StringBuffer as a String.
voidwrite(int oneChar)

This method writes a single character to the output, storing it in the internal buffer.
voidwrite(char[] chars, int offset, int len)

This method writes len chars from the specified array starting at index offset in that array to this stream by appending the chars to the end of the internal buffer.
voidwrite(java.lang.String str)

This method writes the characters in the specified String to the stream by appending them to the end of the internal buffer.
voidwrite(java.lang.String str, int offset, int len)

This method writes out len characters of the specified String to the stream starting at character position offset into the stream.

Constructor Details

StringWriter

public StringWriter()

This method initializes a new StringWriter to write to a StringBuffer initially sized to a default size of 16 chars.


StringWriter

public StringWriter(int size)

This method initializes a new StringWriter to write to a StringBuffer with the specified initial size.

Parameters:


Method Details

close

public void close()

This method closes the stream. The contents of the internal buffer can still be retrieved, but future writes are not guaranteed to work.


flush

public void flush()

This method flushes any buffered characters to the underlying output. It does nothing in this class.


getBuffer

public StringBuffer getBuffer()

This method returns the StringBuffer object that this object is writing to. Note that this is the actual internal buffer, so any operations performed on it will affect this stream object.

Returns:


toString

public String toString()

This method returns the contents of the internal StringBuffer as a String.

Returns:


write

public void write(char[] chars, int offset, int len)

This method writes len chars from the specified array starting at index offset in that array to this stream by appending the chars to the end of the internal buffer.

Parameters:


write

public void write(int oneChar)

This method writes a single character to the output, storing it in the internal buffer.

Parameters:


write

public void write(java.lang.String str)

This method writes the characters in the specified String to the stream by appending them to the end of the internal buffer.

Parameters:


write

public void write(java.lang.String str, int offset, int len)

This method writes out len characters of the specified String to the stream starting at character position offset into the stream. This is done by appending the characters to the internal buffer.

Parameters: