toByteArray()
If the underlying stream is a ByteArrayOutputStream (such as with the no-parameter constructor), this will return the binary UTF8-encoded data that resulted from the character data written to this Writer.

flush

public void flush()
throws java.io.IOException

Flush the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.

Specified by:

flush in interface java.io.Flushable

Specified by:

flush in class java.io.Writer

Throws:

java.io.IOException - If an I/O error occurs

close

public void close()
throws java.io.IOException

Close the stream, flushing it first. Once a stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously-closed stream, however, has no effect.

Specified by:

close in interface java.io.Closeable

Specified by:

close in class java.io.Writer

Throws:

java.io.IOException - If an I/O error occurs

toByteArray

public byte[] toByteArray()

If the underlying stream is a ByteArrayOutputStream (such as with the no-parameter constructor), this will return the binary UTF8-encoded data that resulted from the character data written to this Writer.

Returns:

a byte array of the UTF8 data

Throws:

java.lang.ClassCastException - if the underlying stream is not ByteArrayOutputStream