public class CharEncoderOutputStream extends OutputStream
Accepts raw bytes, and writes the encoded characters.
Counter-part to CharDecoderWriter
.
This is a push-interface; CharEncoderReader
is the equivalent pull-interface.
Can be adapted to write bytes to the consumer (instead of characters)
by using a OutputStreamWriter
as the Writer
.
Can also be adapted to accept characters from the provider (instead of raw bytes)
by wrapping in a OutputStreamWriter
.
Modifier and Type | Field and Description |
---|---|
protected IByteToCharEncoder |
encoder |
protected ByteBuffer |
readBuffer |
protected byte[] |
singleByte |
protected CharBuffer |
writeBuffer |
protected Writer |
writer |
Constructor and Description |
---|
CharEncoderOutputStream(IByteToCharEncoder encoder,
Writer writer) |
CharEncoderOutputStream(IByteToCharEncoder encoder,
Writer writer,
int readBufferSize) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Convenience method that calls
close(boolean) with true . |
void |
close(boolean closeParent)
Must be called when there is no more data to encode.
|
void |
flush() |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
protected void |
writeBuffer(CoderResult cr) |
write
protected IByteToCharEncoder encoder
protected Writer writer
protected ByteBuffer readBuffer
protected CharBuffer writeBuffer
protected byte[] singleByte
public CharEncoderOutputStream(IByteToCharEncoder encoder, Writer writer)
public CharEncoderOutputStream(IByteToCharEncoder encoder, Writer writer, int readBufferSize)
public void write(int b) throws IOException
write
in class OutputStream
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in class OutputStream
IOException
protected void writeBuffer(CoderResult cr) throws IOException
IOException
public void flush() throws IOException
flush
in interface Flushable
flush
in class OutputStream
IOException
public void close() throws IOException
Convenience method that calls close(boolean)
with true
.
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
public void close(boolean closeParent) throws IOException
Must be called when there is no more data to encode. This finishes the encoding, writes any finishing characters required by the encoder, flushes the parent writer, and resets the encoder for possible reuse.
closeParent
- If true
, Writer.close()
will be called on the parent.
If false
, only will be called
, allowing for
additional data to be written to the parent before closing it.IOException
Copyright © 2009–2017 Mark A. Ziesemer. All rights reserved.