Top Description Fields Constructors Methods
org.xerial.snappy

public Class SnappyInputStream

extends InputStream
Class Inheritance
Imports
java.io.ByteArrayInputStream, .IOException, .InputStream

A stream filter for reading data compressed by SnappyOutputStream.
Author
leo

Field Summary

Modifier and TypeField and Description
private byte[]
private boolean
private byte[]
protected final InputStream
public static final int
private final int
private byte[]
private int
private int

Constructor Summary

AccessConstructor and Description
public
SnappyInputStream(InputStream input)

Create a filter for reading compressed data as a uncompressed stream

public
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 TypeMethod and Description
public int
available()

Overrides java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected.

public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Close the stream

protected boolean
private static boolean
isValidHeader(byte[] header)

public int

Returns:

written bytes
rawRead
(Object array, int byteOffset, int byteLength)

Read uncompressed data into the specified array

public int
read(byte[]
the buffer into which the data is read.
b
,
int
the start offset in array b at which the data is written.
byteOffset
,
int
the maximum number of bytes to read.
byteLength
)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.

public int

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.
read
(long[]
input
d
,
int
offset
off
,
int
the number of long elements to read
len
)

Read long array from the stream

public int

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.
read
(long[] d)

Read long array from the stream

public int

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.
read
(double[]
input
d
,
int
offset
off
,
int
the number of double elements to read
len
)

Read double array from the stream

public int

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.
read
(double[] d)

Read double array from the stream

public int

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.
read
(int[] d)

Read int array from the stream

public int

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.
read
(int[]
input
d
,
int
offset
off
,
int
the number of int elements to read
len
)

Read int array from the stream

public int

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.
read
(float[]
input
d
,
int
offset
off
,
int
the number of float elements to read
len
)

Read float array from the stream

public int

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.
read
(float[] d)

Read float array from the stream

public int

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.
read
(short[]
input
d
,
int
offset
off
,
int
the number of short elements to read
len
)

Read short array from the stream

public int

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.
read
(short[] d)

Read short array from the stream

public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of uncompressed data from the input stream.

protected void
readFully(byte[] fragment, int fragmentLength)

protected void
private int

Returns:

read bytes
readNext
(byte[] dest, int offset, int len)

Read next len bytes

Inherited from java.io.InputStream:
markmarkSupportednullInputStreamreadreadAllBytesreadNBytesreadNBytesresetskipskipNBytestransferTo

Field Detail

compressedback to summary
private byte[] compressed
finishedReadingback to summary
private boolean finishedReading
inback to summary
protected final InputStream in
MAX_CHUNK_SIZEback to summary
public static final int MAX_CHUNK_SIZE
maxChunkSizeback to summary
private final int maxChunkSize
uncompressedback to summary
private byte[] uncompressed
uncompressedCursorback to summary
private int uncompressedCursor
uncompressedLimitback to summary
private int uncompressedLimit

Constructor Detail

SnappyInputStreamback to summary
public SnappyInputStream(InputStream input) throws IOException

Create a filter for reading compressed data as a uncompressed stream

SnappyInputStreamback to summary
public SnappyInputStream(InputStream input, int maxChunkSize) throws IOException

Create a filter for reading compressed data as a uncompressed stream with provided maximum chunk size

Method Detail

availableback to summary
public int available() throws IOException

Overrides java.io.InputStream.available.

Doc from java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.

A subclass's implementation of this method may choose to throw an IOException if this input stream has been closed by invoking the close() method.

Returns:int

an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking or 0 when it reaches the end of the input stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Close the stream

Annotations
@Override
Exceptions
IOException:

Doc from java.io.InputStream.close.

if an I/O error occurs.

hasNextChunkback to summary
protected boolean hasNextChunk() throws IOException
isValidHeaderback to summary
private static boolean isValidHeader(byte[] header) throws IOException
rawReadback to summary
public int rawRead(Object array, int byteOffset, int byteLength) throws IOException

Read uncompressed data into the specified array

Returns:int

written bytes

readback to summary
public int read(byte[] b, int byteOffset, int byteLength) throws IOException

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.

Parameters
b:byte[]

Doc from java.io.InputStream.read.

the buffer into which the data is read.

byteOffset:int

Doc from java.io.InputStream.read.

the start offset in array b at which the data is written.

byteLength:int

Doc from java.io.InputStream.read.

the maximum number of bytes to read.

Returns:int

Doc from java.io.InputStream.read.

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.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.InputStream.read.

If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.

readback to summary
public int read(long[] d, int off, int len) throws IOException

Read long array from the stream

Parameters
d:long[]

input

off:int

offset

len:int

the number of long elements to read

Returns:int

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.

readback to summary
public int read(long[] d) throws IOException

Read long array from the stream

Returns:int

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.

readback to summary
public int read(double[] d, int off, int len) throws IOException

Read double array from the stream

Parameters
d:double[]

input

off:int

offset

len:int

the number of double elements to read

Returns:int

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.

readback to summary
public int read(double[] d) throws IOException

Read double array from the stream

Returns:int

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.

readback to summary
public int read(int[] d) throws IOException

Read int array from the stream

Returns:int

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.

readback to summary
public int read(int[] d, int off, int len) throws IOException

Read int array from the stream

Parameters
d:int[]

input

off:int

offset

len:int

the number of int elements to read

Returns:int

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.

readback to summary
public int read(float[] d, int off, int len) throws IOException

Read float array from the stream

Parameters
d:float[]

input

off:int

offset

len:int

the number of float elements to read

Returns:int

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.

readback to summary
public int read(float[] d) throws IOException

Read float array from the stream

Returns:int

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.

readback to summary
public int read(short[] d, int off, int len) throws IOException

Read short array from the stream

Parameters
d:short[]

input

off:int

offset

len:int

the number of short elements to read

Returns:int

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.

readback to summary
public int read(short[] d) throws IOException

Read short array from the stream

Returns:int

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.

readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

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.

Returns:int

Doc from java.io.InputStream.read.

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.InputStream.read.

if an I/O error occurs.

readFullyback to summary
protected void readFully(byte[] fragment, int fragmentLength) throws IOException
readHeaderback to summary
protected void readHeader() throws IOException
readNextback to summary
private int readNext(byte[] dest, int offset, int len) throws IOException

Read next len bytes

Returns:int

read bytes