Class LZFInputStream

java.lang.Object
java.io.InputStream
com.ning.compress.lzf.LZFInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class LZFInputStream extends InputStream
Decorator InputStream implementation used for reading compressed data and uncompressing it on the fly, such that reads return uncompressed data. Its direct counterpart is LZFOutputStream; but there is also LZFCompressingInputStream which does reverse of this class.
See Also:
  • Field Details

    • _decoder

      protected final ChunkDecoder _decoder
      Underlying decoder in use.
    • _recycler

      protected final BufferRecycler _recycler
      Object that handles details of buffer recycling
    • _inputStream

      protected final InputStream _inputStream
      stream to be decompressed
    • _inputStreamClosed

      protected boolean _inputStreamClosed
      Flag that indicates if we have already called 'inputStream.close()' (to avoid calling it multiple times)
    • _cfgFullReads

      protected boolean _cfgFullReads
      Flag that indicates whether we force full reads (reading of as many bytes as requested), or 'optimal' reads (up to as many as available, but at least one). Default is false, meaning that 'optimal' read is used.
    • _inputBuffer

      protected byte[] _inputBuffer
      the current buffer of compressed bytes (from which to decode)
    • _decodedBytes

      protected byte[] _decodedBytes
      the buffer of uncompressed bytes from which content is read
    • _bufferPosition

      protected int _bufferPosition
      The current position (next char to output) in the uncompressed bytes buffer.
    • _bufferLength

      protected int _bufferLength
      Length of the current uncompressed bytes buffer
  • Constructor Details

  • Method Details

    • setUseFullReads

      public void setUseFullReads(boolean b)
      Method that can be used define whether reads should be "full" or "optimal": former means that full compressed blocks are read right away as needed, optimal that only smaller chunks are read at a time, more being read as needed.
    • available

      public int available()
      Method is overridden to report number of bytes that can now be read from decoded data buffer, without reading bytes from the underlying stream. Never throws an exception; returns number of bytes available without further reads from underlying source; -1 if stream has been closed, or 0 if an actual read (and possible blocking) is needed to find out.
      Overrides:
      available in class InputStream
    • read

      public int read() throws IOException
      Specified by:
      read in class InputStream
      Throws:
      IOException
    • read

      public int read(byte[] buffer) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • read

      public int read(byte[] buffer, int offset, int length) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException
    • skip

      public long skip(long n) throws IOException
      Overridden to implement efficient skipping by skipping full chunks whenever possible.
      Overrides:
      skip in class InputStream
      Throws:
      IOException
    • getUnderlyingInputStream

      public InputStream getUnderlyingInputStream()
      Method that can be used to find underlying InputStream that we read from to get LZF encoded data to decode. Will never return null; although underlying stream may be closed (if this stream has been closed).
    • discardBuffered

      public void discardBuffered()
      Method that can be called to discard any already buffered input, read from input source. Specialized method that only makes sense if the underlying InputStream can be repositioned reliably.
    • readAndWrite

      public int readAndWrite(OutputStream out) throws IOException
      Convenience method that will read and uncompress all data available, and write it using given OutputStream. This avoids having to make an intermediate copy of uncompressed data which would be needed when doing the same manually.
      Parameters:
      out - OutputStream to use for writing content
      Returns:
      Number of bytes written (uncompressed)
      Throws:
      IOException
    • readyBuffer

      protected boolean readyBuffer() throws IOException
      Fill the uncompressed bytes buffer by reading the underlying inputStream.
      Returns:
      True if there is now at least one byte to read in the buffer; false if there is no more content to read
      Throws:
      IOException