public class WriterOutputStream extends OutputStream
processBytesBuffer(boolean) is invoked. This takes care to decode bytes into
characters using UTF-8 decoder and write them to output buffer. On output stream explicit flush or close or on input
buffer overflow, output buffer is transfered to underlying target writer.| Modifier and Type | Field and Description |
|---|---|
private static int |
BYTES_BUFFER_SIZE
Size of internal bytes buffer.
|
private ByteBuffer |
bytesBuffer
Bytes buffer used as input for the decoder.
|
private static int |
CHARACTERS_BUFFER_SIZE
Size of internal characters buffer.
|
private CharBuffer |
charactersBuffer
Characters buffer used as output for the decoder.
|
private CharsetDecoder |
decoder
Decode characters from UTF-8 bytes.
|
private Writer |
writer
Target writer.
|
| Constructor and Description |
|---|
WriterOutputStream(Writer writer)
Constructs output stream for target writer, using UTF-8 decoder.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close output stream.
|
void |
flush()
Flush output stream.
|
private void |
flushCharactersBuffer()
Flush characters buffer to underlying writer.
|
private void |
processBytesBuffer(boolean endOfInput)
Decode the contents of input bytes buffer into the characters buffer.
|
void |
write(byte[] b)
Write bytes from the specified byte array to the stream.
|
void |
write(byte[] b,
int off,
int len)
Write bytes from the specified byte array to the stream.
|
void |
write(int b)
Write a single byte to the stream.
|
private static final int BYTES_BUFFER_SIZE
bytesBuffer.private static final int CHARACTERS_BUFFER_SIZE
charactersBuffer.private final CharsetDecoder decoder
bytesBuffer and writes characters to
charactersBuffer.private final ByteBuffer bytesBuffer
private final CharBuffer charactersBuffer
private final Writer writer
public WriterOutputStream(Writer writer)
writer - target writer.public void write(byte[] b,
int off,
int len)
throws IOException
write in class OutputStreamb - the byte array containing the bytes to write,off - the start offset in the byte array,len - the number of bytes to write.IOException - if writing operation to underlying target writer fails.public void write(byte[] b)
throws IOException
write(byte[], int, int) using entire buffer.write in class OutputStreamb - the byte array containing the bytes to write.IOException - if writing operation to underlying target writer fails.public void write(int b)
throws IOException
processBytesBuffer(boolean) first.write in class OutputStreamb - the byte to write.IOException - if writing operation to underlying target writer fails.public void flush()
throws IOException
writer and writer flushed.flush in interface Flushableflush in class OutputStreamIOException - if writing operation to underlying target writer fails.public void close()
throws IOException
writer via characters buffer. After that Writer.close() will be called.close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOException - if writing or close operation on underlying target writer fails.private void processBytesBuffer(boolean endOfInput)
throws IOException
flushCharactersBuffer() to commit buffer to underlying writer.endOfInput - signal that end of input was reached.IOException - if writing operation to underlying target writer fails.private void flushCharactersBuffer()
throws IOException
IOException - if write operation on underlying writer fails.Copyright © 2018. All rights reserved.