Class SnappyCompressorInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.commons.compress.compressors.CompressorInputStream
-
- org.apache.commons.compress.compressors.lz77support.AbstractLZ77CompressorInputStream
-
- org.apache.commons.compress.compressors.snappy.SnappyCompressorInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,InputStreamStatistics
public class SnappyCompressorInputStream extends AbstractLZ77CompressorInputStream
CompressorInputStream for the raw Snappy format.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.
- Since:
- 1.7
- See Also:
- Snappy compressed format description
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SnappyCompressorInputStream.State
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_BLOCK_SIZE
Default block sizeprivate boolean
endReached
private int
size
The size of the uncompressed dataprivate SnappyCompressorInputStream.State
state
Current state of the streamprivate static int
TAG_MASK
Mask used to determine the type of "tag" is being processedprivate int
uncompressedBytesRemaining
Number of uncompressed bytes still to be read.-
Fields inherited from class org.apache.commons.compress.compressors.lz77support.AbstractLZ77CompressorInputStream
supplier
-
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
fill()
Try to fill the buffer with the next block of data.int
getSize()
Get the uncompressed size of the streamint
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.-
Methods inherited from class org.apache.commons.compress.compressors.lz77support.AbstractLZ77CompressorInputStream
available, close, getCompressedCount, hasMoreDataInBlock, prefill, read, readBackReference, readLiteral, readOneByte, startBackReference, startLiteral
-
Methods inherited from class org.apache.commons.compress.compressors.CompressorInputStream
count, count, getBytesRead, getCount, getUncompressedCount, pushedBackBytes
-
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
-
Methods inherited from interface org.apache.commons.compress.utils.InputStreamStatistics
getUncompressedCount
-
-
-
-
Field Detail
-
TAG_MASK
private static final int TAG_MASK
Mask used to determine the type of "tag" is being processed- See Also:
- Constant Field Values
-
DEFAULT_BLOCK_SIZE
public static final int DEFAULT_BLOCK_SIZE
Default block size- See Also:
- Constant Field Values
-
size
private final int size
The size of the uncompressed data
-
uncompressedBytesRemaining
private int uncompressedBytesRemaining
Number of uncompressed bytes still to be read.
-
state
private SnappyCompressorInputStream.State state
Current state of the stream
-
endReached
private boolean endReached
-
-
Constructor Detail
-
SnappyCompressorInputStream
public SnappyCompressorInputStream(java.io.InputStream is) throws java.io.IOException
Constructor using the default buffer size of 32k.- Parameters:
is
- An InputStream to read compressed data from- Throws:
java.io.IOException
- if reading fails
-
SnappyCompressorInputStream
public SnappyCompressorInputStream(java.io.InputStream is, int blockSize) throws java.io.IOException
Constructor using a configurable buffer size.- Parameters:
is
- An InputStream to read compressed data fromblockSize
- The block size used in compression- Throws:
java.io.IOException
- if reading failsjava.lang.IllegalArgumentException
- if blockSize is not bigger than 0
-
-
Method Detail
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
fill
private void fill() throws java.io.IOException
Try to fill the buffer with the next block of data.- Throws:
java.io.IOException
-
readLiteralLength
private int readLiteralLength(int b) throws java.io.IOException
- Throws:
java.io.IOException
-
readSize
private long readSize() throws java.io.IOException
The stream starts with the uncompressed length (up to a maximum of 2^32 - 1), stored as a little-endian varint. Varints consist of a series of bytes, where the lower 7 bits are data and the upper bit is set iff there are more bytes to be read. In other words, an uncompressed length of 64 would be stored as 0x40, and an uncompressed length of 2097150 (0x1FFFFE) would be stored as 0xFE 0xFF 0x7F.- Returns:
- The size of the uncompressed data
- Throws:
java.io.IOException
- Could not read a byte
-
getSize
public int getSize()
Get the uncompressed size of the stream- Overrides:
getSize
in classAbstractLZ77CompressorInputStream
- Returns:
- the uncompressed size
-
-