|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.Writer
java.io.StringWriter
public class StringWriter
This class writes chars to an internal StringBuffer that
can then be used to retrieve a String.
| Field Summary |
|---|
| Fields inherited from class java.io.Writer |
|---|
lock |
| 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 | |
|---|---|
void |
close()
This method closes the stream. |
void |
flush()
This method flushes any buffered characters to the underlying output. |
StringBuffer |
getBuffer()
This method returns the StringBuffer object that this
object is writing to. |
String |
toString()
This method returns the contents of the internal StringBuffer
as a String. |
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. |
void |
write(int oneChar)
This method writes a single character to the output, storing it in the internal buffer. |
void |
write(String str)
This method writes the characters in the specified String
to the stream by appending them to the end of the internal buffer. |
void |
write(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. |
| Methods inherited from class java.io.Writer |
|---|
append, append, append, write |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public StringWriter()
StringWriter to write to a
StringBuffer initially sized to a default size of 16
chars.
public StringWriter(int size)
StringWriter to write to a
StringBuffer with the specified initial size.
size - The initial size to make the StringBuffer| Method Detail |
|---|
public void close()
throws IOException
close in interface Closeableclose in class WriterIOException - If an error orrurs.public void flush()
flush in interface Flushableflush in class Writerpublic StringBuffer getBuffer()
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.
StringBuffer object being written topublic String toString()
StringBuffer
as a String.
toString in class ObjectString representing the chars written to
this stream.public void write(int oneChar)
write in class WriteroneChar - The char to write, passed as an int.
public void write(char[] chars,
int offset,
int len)
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.
write in class Writerchars - The array of chars to writeoffset - The index into the array to start writing fromlen - The number of chars to writepublic void write(String str)
String
to the stream by appending them to the end of the internal buffer.
write in class Writerstr - The String to write to the stream.
public void write(String str,
int offset,
int len)
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.
write in class Writerstr - The String to write characters fromoffset - The character position to start writing fromlen - The number of characters to write.
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||