Class LZFFileInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class LZFFileInputStream
    extends FileInputStream
    Helper class that allows use of LZF compression even if a library requires use of FileInputStream.

    Note that use of this class is not recommended unless you absolutely must use a FileInputStream instance; otherwise basic LZFInputStream (which uses aggregation for underlying streams) is more appropriate

    Implementation note: much of the code is just copied from LZFInputStream, so care must be taken to keep implementations in sync if there are fixes.

    • Field Detail

      • _decompressor

        protected final ChunkDecoder _decompressor
        Underlying decoder in use.
      • _recycler

        protected final BufferRecycler _recycler
        Object that handles details of buffer recycling
      • _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
      • _wrapper

        protected final com.ning.compress.lzf.util.LZFFileInputStream.Wrapper _wrapper
        Wrapper object we use to allow decoder to read directly from the stream, without ending in infinite loop...
    • Method Detail

      • 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.
      • skip

        public long skip​(long n)
                  throws IOException
        Overridden to implement efficient skipping by skipping full chunks whenever possible.
        Overrides:
        skip in class FileInputStream
        Throws:
        IOException
      • 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.
        Throws:
        IOException
      • readRaw

        protected final int readRaw​(byte[] buffer,
                                    int offset,
                                    int length)
                             throws IOException
        Throws:
        IOException