public class SnappyCompressorInputStream extends AbstractLZ77CompressorInputStream
This implementation uses an internal buffer in order to handle the back-references that are at the heart of the LZ77 algorithm. The size of the buffer must be at least as big as the biggest offset used in the compressed stream. The current version of the Snappy algorithm as defined by Google works on 32k blocks and doesn't contain offsets bigger than 32k which is the default block size used by this class.
Modifier and Type | Class and Description |
---|---|
private static class |
SnappyCompressorInputStream.State |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BLOCK_SIZE
Default block size
|
private boolean |
endReached |
private int |
size
The size of the uncompressed data
|
private SnappyCompressorInputStream.State |
state
Current state of the stream
|
private static int |
TAG_MASK
Mask used to determine the type of "tag" is being processed
|
private int |
uncompressedBytesRemaining
Number of uncompressed bytes still to be read.
|
supplier
Constructor and Description |
---|
SnappyCompressorInputStream(java.io.InputStream is)
Constructor using the default buffer size of 32k.
|
SnappyCompressorInputStream(java.io.InputStream is,
int blockSize)
Constructor using a configurable buffer size.
|
Modifier and Type | Method and Description |
---|---|
private void |
fill()
Try to fill the buffer with the next block of data.
|
int |
getSize()
Get the uncompressed size of the stream
|
int |
read(byte[] b,
int off,
int len) |
private int |
readLiteralLength(int b) |
private long |
readSize()
The stream starts with the uncompressed length (up to a maximum of 2^32 -
1), stored as a little-endian varint.
|
available, close, getCompressedCount, hasMoreDataInBlock, prefill, read, readBackReference, readLiteral, readOneByte, startBackReference, startLiteral
count, count, getBytesRead, getCount, getUncompressedCount, pushedBackBytes
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getUncompressedCount
private static final int TAG_MASK
public static final int DEFAULT_BLOCK_SIZE
private final int size
private int uncompressedBytesRemaining
private SnappyCompressorInputStream.State state
private boolean endReached
public SnappyCompressorInputStream(java.io.InputStream is) throws java.io.IOException
is
- An InputStream to read compressed data fromjava.io.IOException
- if reading failspublic SnappyCompressorInputStream(java.io.InputStream is, int blockSize) throws java.io.IOException
is
- An InputStream to read compressed data fromblockSize
- The block size used in compressionjava.io.IOException
- if reading failspublic int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
private void fill() throws java.io.IOException
java.io.IOException
private int readLiteralLength(int b) throws java.io.IOException
java.io.IOException
private long readSize() throws java.io.IOException
java.io.IOException
- Could not read a bytepublic int getSize()
getSize
in class AbstractLZ77CompressorInputStream