Class LZFCompressingInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class LZFCompressingInputStream
    extends java.io.InputStream
    Decorator InputStream implementation used for reading uncompressed data and compressing it on the fly, such that reads return compressed data. It is reverse of LZFInputStream (which instead uncompresses data).
    See Also:
    LZFInputStream
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int _bufferLength
      Length of the current uncompressed bytes buffer
      protected int _bufferPosition
      The current position (next char to output) in the uncompressed bytes buffer.
      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).
      protected byte[] _encodedBytes
      Buffer that contains compressed data that is returned to readers.
      private ChunkEncoder _encoder  
      protected byte[] _inputBuffer
      Buffer in which uncompressed input is first read, before getting encoded in _encodedBytes.
      protected java.io.InputStream _inputStream
      Stream used for reading data to be compressed
      protected boolean _inputStreamClosed
      Flag that indicates if we have already called 'inputStream.close()' (to avoid calling it multiple times)
      protected int _readCount
      Number of bytes read from the underlying _inputStream
      private BufferRecycler _recycler  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void _closeInput()  
      int available()  
      void close()  
      int read()  
      int read​(byte[] buffer)  
      int read​(byte[] buffer, int offset, int length)  
      protected boolean readyBuffer()
      Fill the uncompressed bytes buffer by reading the underlying inputStream.
      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.
      long skip​(long n)
      Overridden to just skip at most a single chunk at a time
      • Methods inherited from class java.io.InputStream

        mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • _inputStream

        protected final java.io.InputStream _inputStream
        Stream used for reading data to be compressed
      • _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
        Buffer in which uncompressed input is first read, before getting encoded in _encodedBytes.
      • _encodedBytes

        protected byte[] _encodedBytes
        Buffer that contains compressed data that is returned to readers.
      • _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
      • _readCount

        protected int _readCount
        Number of bytes read from the underlying _inputStream
    • Constructor Detail

      • LZFCompressingInputStream

        public LZFCompressingInputStream​(java.io.InputStream in)
      • LZFCompressingInputStream

        public LZFCompressingInputStream​(ChunkEncoder encoder,
                                         java.io.InputStream in)
      • LZFCompressingInputStream

        public LZFCompressingInputStream​(ChunkEncoder encoder,
                                         java.io.InputStream in,
                                         BufferRecycler bufferRecycler)
    • 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.
      • available

        public int available()
        Overrides:
        available in class java.io.InputStream
      • read

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

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

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

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException
      • _closeInput

        private void _closeInput()
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Overridden to just skip at most a single chunk at a time
        Overrides:
        skip in class java.io.InputStream
        Throws:
        java.io.IOException
      • readyBuffer

        protected boolean readyBuffer()
                               throws java.io.IOException
        Fill the uncompressed bytes buffer by reading the underlying inputStream.
        Throws:
        java.io.IOException