Class SnappyInputStream

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

    public class SnappyInputStream
    extends java.io.InputStream
    A stream filter for reading data compressed by SnappyOutputStream.
    • Constructor Summary

      Constructors 
      Constructor Description
      SnappyInputStream​(java.io.InputStream input)
      Create a filter for reading compressed data as a uncompressed stream
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()
      Close the stream
      protected boolean hasNextChunk()  
      private static boolean isValidHeader​(byte[] header)  
      int rawRead​(java.lang.Object array, int byteOffset, int byteLength)
      Read uncompressed data into the specified array
      int read()
      Reads the next byte of uncompressed data from the input stream.
      int read​(byte[] b, int byteOffset, int byteLength)
      Reads up to len bytes of data from the input stream into an array of bytes.
      int read​(double[] d)
      Read double array from the stream
      int read​(double[] d, int off, int len)
      Read double array from the stream
      int read​(float[] d)
      Read float array from the stream
      int read​(float[] d, int off, int len)
      Read float array from the stream
      int read​(int[] d)
      Read int array from the stream
      int read​(int[] d, int off, int len)
      Read int array from the stream
      int read​(long[] d)
      Read long array from the stream
      int read​(long[] d, int off, int len)
      Read long array from the stream
      int read​(short[] d)
      Read short array from the stream
      int read​(short[] d, int off, int len)
      Read short array from the stream
      protected void readFully​(byte[] fragment, int fragmentLength)  
      protected void readHeader()  
      private int readNext​(byte[] dest, int offset, int len)
      Read next len bytes
      • Methods inherited from class java.io.InputStream

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

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

      • finishedReading

        private boolean finishedReading
      • in

        protected final java.io.InputStream in
      • compressed

        private byte[] compressed
      • uncompressed

        private byte[] uncompressed
      • uncompressedCursor

        private int uncompressedCursor
      • uncompressedLimit

        private int uncompressedLimit
      • header

        private byte[] header
    • Constructor Detail

      • SnappyInputStream

        public SnappyInputStream​(java.io.InputStream input)
                          throws java.io.IOException
        Create a filter for reading compressed data as a uncompressed stream
        Parameters:
        input -
        Throws:
        java.io.IOException
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Close the stream
        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
      • readHeader

        protected void readHeader()
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • isValidHeader

        private static boolean isValidHeader​(byte[] header)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • readFully

        protected void readFully​(byte[] fragment,
                                 int fragmentLength)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int byteOffset,
                        int byteLength)
                 throws java.io.IOException
        Reads up to len bytes of data from the input stream into an array of bytes.
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • rawRead

        public int rawRead​(java.lang.Object array,
                           int byteOffset,
                           int byteLength)
                    throws java.io.IOException
        Read uncompressed data into the specified array
        Parameters:
        array -
        byteOffset -
        byteLength -
        Returns:
        written bytes
        Throws:
        java.io.IOException
      • read

        public int read​(long[] d,
                        int off,
                        int len)
                 throws java.io.IOException
        Read long array from the stream
        Parameters:
        d - input
        off - offset
        len - the number of long elements to read
        Returns:
        the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
        Throws:
        java.io.IOException
      • read

        public int read​(long[] d)
                 throws java.io.IOException
        Read long array from the stream
        Parameters:
        d -
        Returns:
        the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
        Throws:
        java.io.IOException
      • read

        public int read​(double[] d,
                        int off,
                        int len)
                 throws java.io.IOException
        Read double array from the stream
        Parameters:
        d - input
        off - offset
        len - the number of double elements to read
        Returns:
        the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
        Throws:
        java.io.IOException
      • read

        public int read​(double[] d)
                 throws java.io.IOException
        Read double array from the stream
        Parameters:
        d -
        Returns:
        the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
        Throws:
        java.io.IOException
      • read

        public int read​(int[] d)
                 throws java.io.IOException
        Read int array from the stream
        Parameters:
        d -
        Returns:
        the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
        Throws:
        java.io.IOException
      • read

        public int read​(int[] d,
                        int off,
                        int len)
                 throws java.io.IOException
        Read int array from the stream
        Parameters:
        d - input
        off - offset
        len - the number of int elements to read
        Returns:
        the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
        Throws:
        java.io.IOException
      • read

        public int read​(float[] d,
                        int off,
                        int len)
                 throws java.io.IOException
        Read float array from the stream
        Parameters:
        d - input
        off - offset
        len - the number of float elements to read
        Returns:
        the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
        Throws:
        java.io.IOException
      • read

        public int read​(float[] d)
                 throws java.io.IOException
        Read float array from the stream
        Parameters:
        d -
        Returns:
        the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
        Throws:
        java.io.IOException
      • read

        public int read​(short[] d,
                        int off,
                        int len)
                 throws java.io.IOException
        Read short array from the stream
        Parameters:
        d - input
        off - offset
        len - the number of short elements to read
        Returns:
        the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
        Throws:
        java.io.IOException
      • read

        public int read​(short[] d)
                 throws java.io.IOException
        Read short array from the stream
        Parameters:
        d -
        Returns:
        the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
        Throws:
        java.io.IOException
      • readNext

        private int readNext​(byte[] dest,
                             int offset,
                             int len)
                      throws java.io.IOException
        Read next len bytes
        Parameters:
        dest -
        offset -
        len -
        Returns:
        read bytes
        Throws:
        java.io.IOException
      • hasNextChunk

        protected boolean hasNextChunk()
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        public int read()
                 throws java.io.IOException
        Reads the next byte of uncompressed data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.InputStream
        Throws:
        java.io.IOException