Class SnappyInputStream

java.lang.Object
java.io.InputStream
org.xerial.snappy.SnappyInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class SnappyInputStream extends InputStream
A stream filter for reading data compressed by SnappyOutputStream.
Author:
leo
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final InputStream
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a filter for reading compressed data as a uncompressed stream
    SnappyInputStream(InputStream input, int maxChunkSize)
    Create a filter for reading compressed data as a uncompressed stream with provided maximum chunk size
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    void
    Close the stream
    protected boolean
     
    int
    rawRead(Object array, int byteOffset, int byteLength)
    Read uncompressed data into the specified array
    int
    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
     

    Methods inherited from class Object

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

  • Constructor Details

    • SnappyInputStream

      public SnappyInputStream(InputStream input) throws IOException
      Create a filter for reading compressed data as a uncompressed stream
      Parameters:
      input -
      Throws:
      IOException
    • SnappyInputStream

      public SnappyInputStream(InputStream input, int maxChunkSize) throws IOException
      Create a filter for reading compressed data as a uncompressed stream with provided maximum chunk size
      Parameters:
      input -
      maxChunkSize -
      Throws:
      IOException
  • Method Details

    • close

      public void close() throws IOException
      Close the stream
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException
    • readHeader

      protected void readHeader() throws IOException
      Throws:
      IOException
    • readFully

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

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

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

      public int read(long[] d, int off, int len) throws 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:
      IOException
    • read

      public int read(long[] d) throws 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:
      IOException
    • read

      public int read(double[] d, int off, int len) throws 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:
      IOException
    • read

      public int read(double[] d) throws 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:
      IOException
    • read

      public int read(int[] d) throws 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:
      IOException
    • read

      public int read(int[] d, int off, int len) throws 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:
      IOException
    • read

      public int read(float[] d, int off, int len) throws 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:
      IOException
    • read

      public int read(float[] d) throws 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:
      IOException
    • read

      public int read(short[] d, int off, int len) throws 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:
      IOException
    • read

      public int read(short[] d) throws 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:
      IOException
    • hasNextChunk

      protected boolean hasNextChunk() throws IOException
      Throws:
      IOException
    • read

      public int read() throws 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 InputStream
      Throws:
      IOException
    • available

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