java.lang.Object
java.io.OutputStream
i2p.susi.util.DecodingOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class DecodingOutputStreamextends OutputStream
Buffering decoder that outputs to a Writer. Adapted from SAM UTF8Reader.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final ByteBuffer
    Bytes waiting to be decoded.
    private final CharBuffer
    Characters waiting to be written.
    private final CharsetDecoder
    The decoder doing the work.
    private static final Log
    Logger for this class.
    private final Writer
    Where decoded characters are written.
    private static final int
    Character substituted for undecodable bytes, the Unicode replacement character.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a DecodingOutputStream that decodes bytes and writes characters to the given Writer.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Only flushes.
    private void
    decodeAndWrite(boolean endOfInput)
    Decodes the buffered bytes and writes the result.
    void
    Flush any buffered bytes through the decoder.
    void
    write(byte[] buf, int off, int len)
    Write bytes to be decoded.
    void
    write(int b)
    Write a single byte to be decoded.

    Methods inherited from class OutputStream

    nullOutputStream, write

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _log

      private static final Log _log
      Logger for this class.
    • _out

      private final Writer _out
      Where decoded characters are written.
    • _bb

      private final ByteBuffer _bb
      Bytes waiting to be decoded.
    • _cb

      private final CharBuffer _cb
      Characters waiting to be written.
    • _dc

      private final CharsetDecoder _dc
      The decoder doing the work.
    • REPLACEMENT

      private static final int REPLACEMENT
      Character substituted for undecodable bytes, the Unicode replacement character.
      See Also:
  • Constructor Details

    • DecodingOutputStream

      public DecodingOutputStream(Writer out, String charset) throws UnsupportedEncodingException
      Create a DecodingOutputStream that decodes bytes and writes characters to the given Writer.
      Parameters:
      out - the Writer to write decoded characters to
      charset - the charset to decode (e.g. "UTF-8")
      Throws:
      UnsupportedEncodingException - on unknown charset
  • Method Details

    • write

      public void write(int b) throws IOException
      Write a single byte to be decoded.
      Specified by:
      write in class OutputStream
      Parameters:
      b - the byte to write
      Throws:
      IOException - on I/O error
    • write

      public void write(byte[] buf, int off, int len) throws IOException
      Write bytes to be decoded.
      Overrides:
      write in class OutputStream
      Parameters:
      buf - the buffer of bytes to write
      off - the start offset in the buffer
      len - the number of bytes to write
      Throws:
      IOException - on I/O error
    • decodeAndWrite

      private void decodeAndWrite(boolean endOfInput) throws IOException
      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

      public void flush() throws IOException
      Flush any buffered bytes through the decoder.
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException - on I/O error
    • close

      public void close() throws IOException
      Only flushes. Does NOT close the writer.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException