java.lang.Object | ||
↳ | java.io.Writer | |
↳ | java.io.StringWriter |
A specialized Writer that writes characters to a StringBuffer
in a sequential manner, appending them in the process. The result can later
be queried using the StringWriter(int) or toString()
methods.
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.io.Writer
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
StringWriter which has a StringBuffer
allocated with the default size of 16 characters. | |||||||||||
Constructs a new
StringWriter which has a StringBuffer
allocated with a size of initialSize characters. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Appends the character sequence
csq to this writer's StringBuffer . | |||||||||||
Appends a subsequence of the character sequence
csq to this
writer's StringBuffer . | |||||||||||
Appends the character
c to this writer's StringBuffer . | |||||||||||
Calling this method has no effect.
| |||||||||||
Calling this method has no effect.
| |||||||||||
Gets a reference to this writer's internal StringBuffer.
| |||||||||||
Gets a copy of the contents of this writer as a string.
| |||||||||||
Writes
count characters starting at offset in buf
to this writer's StringBuffer . | |||||||||||
Writes
count characters from str starting at offset to this writer's StringBuffer . | |||||||||||
Writes one character to this writer's
StringBuffer . | |||||||||||
Writes the characters from the specified string to this writer's
StringBuffer . |
[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 StringWriter
which has a StringBuffer
allocated with the default size of 16 characters. The StringBuffer
is also the lock
used to synchronize access to this
writer.
Constructs a new StringWriter
which has a StringBuffer
allocated with a size of initialSize
characters. The StringBuffer
is also the lock
used to synchronize access to this
writer.
initialSize | the intial size of the target string buffer. |
---|
Appends the character sequence csq
to this writer's StringBuffer
. This method works the same way as StringWriter.write(csq.toString())
. If csq
is null
, then
the string "null" is written to the target stream.
csq | the character sequence appended to the target. |
---|
Appends a subsequence of the character sequence csq
to this
writer's StringBuffer
. This method works the same way as StringWriter.writer(csq.subsequence(start, end).toString())
. If csq
is null
, then the specified subsequence of the string "null"
will be written to the target.
csq | the character sequence appended to the target. |
---|---|
start | the index of the first char in the character sequence appended to the target. |
end | the index of the character following the last character of the subsequence appended to the target. |
IndexOutOfBoundsException | if start > end , start < 0 , end < 0 or
either start or end are greater or equal than
the length of csq . |
---|
Appends the character c
to this writer's StringBuffer
.
This method works the same way as write(int).
c | the character to append to the target stream. |
---|
Calling this method has no effect. In contrast to most Writer
subclasses,
the other methods in StringWriter
do not throw an IOException
if
close()
has been called.
IOException | if an error occurs while closing this writer. |
---|
Calling this method has no effect.
Gets a reference to this writer's internal StringBuffer. Any changes made to the returned buffer are reflected in this writer.
StringBuffer
.Gets a copy of the contents of this writer as a string.
Writes count
characters starting at offset
in buf
to this writer's StringBuffer
.
cbuf | the non-null character array to write. |
---|---|
offset | the index of the first character in cbuf to write. |
count | the maximum number of characters to write. |
IndexOutOfBoundsException | if offset < 0 or count < 0 , or if offset + count is greater than the size of buf . |
---|
Writes count
characters from str
starting at offset
to this writer's StringBuffer
.
str | the non-null string containing the characters to write. |
---|---|
offset | the index of the first character in str to write. |
count | the number of characters from str to write. |
StringIndexOutOfBoundsException | if offset < 0 or count < 0 , or if offset + count is greater than the length of str . |
---|
Writes one character to this writer's StringBuffer
. Only the two
least significant bytes of the integer oneChar
are written.
oneChar | the character to write to this writer's StringBuffer . |
---|
Writes the characters from the specified string to this writer's StringBuffer
.
str | the non-null string containing the characters to write. |
---|