Class LZ4FrameInputStream

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

    public class LZ4FrameInputStream
    extends java.io.FilterInputStream
    Implementation of the v1.5.1 LZ4 Frame format. This class is NOT thread safe.

    Not Supported:

    • Dependent blocks
    • Legacy streams

    Originally based on kafka's KafkaLZ4BlockInputStream.

    See Also:
    LZ4 Framing Format Spec 1.5.1
    • Field Summary

      • Fields inherited from class java.io.FilterInputStream

        in
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()  
      long getExpectedContentSize()
      Returns the optional Content Size value set in Frame Descriptor.
      boolean isExpectedContentSizeDefined()
      Checks if the optionnal Content Size is set (FLG.Bits.CONTENT_SIZE is enabled).
      void mark​(int readlimit)  
      boolean markSupported()  
      int read()  
      int read​(byte[] b, int off, int len)  
      void reset()  
      long skip​(long n)  
      • Methods inherited from class java.io.FilterInputStream

        read
      • Methods inherited from class java.io.InputStream

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

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

      • LZ4FrameInputStream

        public LZ4FrameInputStream​(java.io.InputStream in,
                                   LZ4SafeDecompressor decompressor,
                                   XXHash32 checksum)
                            throws java.io.IOException
        Creates a new InputStream that will decompress data using the LZ4 algorithm. This instance will decompress all concatenated frames in their sequential order.
        Parameters:
        in - the stream to decompress
        decompressor - the decompressor to use
        checksum - the hash function to use
        Throws:
        java.io.IOException - if an I/O error occurs
        See Also:
        LZ4FrameInputStream(InputStream, LZ4SafeDecompressor, XXHash32, boolean)
      • LZ4FrameInputStream

        public LZ4FrameInputStream​(java.io.InputStream in,
                                   LZ4SafeDecompressor decompressor,
                                   XXHash32 checksum,
                                   boolean readSingleFrame)
                            throws java.io.IOException
        Creates a new InputStream that will decompress data using the LZ4 algorithm.
        Parameters:
        in - the stream to decompress
        decompressor - the decompressor to use
        checksum - the hash function to use
        readSingleFrame - whether read is stopped after the first non-skippable frame
        Throws:
        java.io.IOException - if an I/O error occurs
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Overrides:
        read in class java.io.FilterInputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.FilterInputStream
        Throws:
        java.io.IOException
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Overrides:
        skip in class java.io.FilterInputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.FilterInputStream
        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.FilterInputStream
        Throws:
        java.io.IOException
      • mark

        public void mark​(int readlimit)
        Overrides:
        mark in class java.io.FilterInputStream
      • reset

        public void reset()
                   throws java.io.IOException
        Overrides:
        reset in class java.io.FilterInputStream
        Throws:
        java.io.IOException
      • markSupported

        public boolean markSupported()
        Overrides:
        markSupported in class java.io.FilterInputStream
      • getExpectedContentSize

        public long getExpectedContentSize()
                                    throws java.io.IOException
        Returns the optional Content Size value set in Frame Descriptor. If the Content Size is not set (FLG.Bits.CONTENT_SIZE not enabled) in compressed stream, -1L is returned. A call to this method is valid only when this instance is supposed to read only one frame (readSingleFrame == true).
        Returns:
        the expected content size, or -1L if no expected content size is set in the frame.
        Throws:
        java.io.IOException - On input stream read exception
        See Also:
        LZ4FrameInputStream(InputStream, LZ4SafeDecompressor, XXHash32, boolean)
      • isExpectedContentSizeDefined

        public boolean isExpectedContentSizeDefined()
                                             throws java.io.IOException
        Checks if the optionnal Content Size is set (FLG.Bits.CONTENT_SIZE is enabled).
        Returns:
        true if this instance is supposed to read only one frame and if the optional content size is set in the frame.
        Throws:
        java.io.IOException - On input stream read exception