java.lang.Object
java.io.OutputStream
i2p.susi.util.DecodingOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
Buffering decoder that outputs to a Writer. Adapted from SAM UTF8Reader.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ByteBufferBytes waiting to be decoded.private final CharBufferCharacters waiting to be written.private final CharsetDecoderThe decoder doing the work.private static final LogLogger for this class.private final WriterWhere decoded characters are written.private static final intCharacter substituted for undecodable bytes, the Unicode replacement character.Constructor Summary
ConstructorsConstructorDescriptionDecodingOutputStream(Writer out, String charset) Create a DecodingOutputStream that decodes bytes and writes characters to the given Writer.Method Summary
Modifier and TypeMethodDescriptionvoidclose()Only flushes.private voiddecodeAndWrite(boolean endOfInput) Decodes the buffered bytes and writes the result.voidflush()Flush any buffered bytes through the decoder.voidwrite(byte[] buf, int off, int len) Write bytes to be decoded.voidwrite(int b) Write a single byte to be decoded.Methods inherited from class OutputStream
nullOutputStream, write
Field Details
_log
Logger for this class._out
Where decoded characters are written._bb
Bytes waiting to be decoded._cb
Characters waiting to be written._dc
The decoder doing the work.REPLACEMENT
private static final int REPLACEMENTCharacter substituted for undecodable bytes, the Unicode replacement character.- See Also:
Constructor Details
DecodingOutputStream
Create a DecodingOutputStream that decodes bytes and writes characters to the given Writer.- Parameters:
out- the Writer to write decoded characters tocharset- the charset to decode (e.g. "UTF-8")- Throws:
UnsupportedEncodingException- on unknown charset
Method Details
write
Write a single byte to be decoded.- Specified by:
writein classOutputStream- Parameters:
b- the byte to write- Throws:
IOException- on I/O error
write
Write bytes to be decoded.- Overrides:
writein classOutputStream- Parameters:
buf- the buffer of bytes to writeoff- the start offset in the bufferlen- the number of bytes to write- Throws:
IOException- on I/O error
decodeAndWrite
Decodes the buffered bytes and writes the result.- Parameters:
endOfInput- true if no more bytes will follow- Throws:
IOException- if the output cannot be written
flush
Flush any buffered bytes through the decoder.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException- on I/O error
close
Only flushes. Does NOT close the writer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException