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.
The raw Snappy format requires the uncompressed size to be written at the beginning of the stream using a varint representation, i.e. the number of bytes
needed to write the information is not known before the uncompressed size is known. We've chosen to make the uncompressedSize a parameter of the constructor
in favor of buffering the whole output until the size is known. When using the FramedSnappyCompressorOutputStream this limitation is taken care of by
the warpping framing format.
| Modifier and Type | Field and Description |
|---|---|
| private final LZ77Compressor | |
| private final ByteUtils. | |
| private boolean | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private final byte[] | |
| private final OutputStream | |
| private static final int | |
| private static final int | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| public | SnappyCompressorOutputStream(final OutputStream
the outputstream to write compressed data to os, final long the uncompressed size of data uncompressedSize)Constructor using the default block size of 32k. |
| public | SnappyCompressorOutputStream(final OutputStream
the outputstream to write compressed data to os, final long the uncompressed size of data uncompressedSize, final int the block size used - must be a power of two blockSize)Constructor using a configurable block size. |
| public | SnappyCompressorOutputStream(final OutputStream
the outputstream to write compressed data to os, final long the uncompressed size of data uncompressedSize, final Parameters the parameters to use by the compressor - note that the format itself imposes some limits like a maximum match length of 64 bytes params)Constructor providing full control over the underlying LZ77 compressor. |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Overrides java. Implements java. |
| public static Parameters. | Returns: a builder correctly configured for the Snappy algorithm using the gven block sizethe block size. blockSize)Returns a builder correctly configured for the Snappy algorithm using the gven block size. |
| public void | finish()
Compresses all remaining data and writes it to the stream, doesn't close the underlying stream. |
| public void | write(final byte[]
the data. data, final int the start offset in the data. off, final int the number of bytes to write. len)Overrides java. len bytes from the specified byte array
starting at offset off to this output stream.
|
| public void | write(final int
the b)byte.Implements abstract java. |
| private void | |
| private void | |
| private void | writeBackReferenceWithLittleEndianOffset(final int tag, final int offsetBytes, final int len, final int offset)
|
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | writeLiteralBlockWithSize(final int tagByte, final int sizeBytes, final int len, final LZ77Compressor.
|
| private void | |
| private void |
| compressor | back to summary |
|---|---|
| private final LZ77Compressor compressor | |
| consumer | back to summary |
|---|---|
| private final ByteUtils. | |
| finished | back to summary |
|---|---|
| private boolean finished | |
| FOUR_BYTE_COPY_TAG | back to summary |
|---|---|
| private static final int FOUR_BYTE_COPY_TAG | |
| FOUR_SIZE_BYTE_MARKER | back to summary |
|---|---|
| private static final int FOUR_SIZE_BYTE_MARKER | |
| MAX_LITERAL_SIZE_WITH_ONE_SIZE_BYTE | back to summary |
|---|---|
| private static final int MAX_LITERAL_SIZE_WITH_ONE_SIZE_BYTE | |
| MAX_LITERAL_SIZE_WITH_THREE_SIZE_BYTES | back to summary |
|---|---|
| private static final int MAX_LITERAL_SIZE_WITH_THREE_SIZE_BYTES | |
| MAX_LITERAL_SIZE_WITH_TWO_SIZE_BYTES | back to summary |
|---|---|
| private static final int MAX_LITERAL_SIZE_WITH_TWO_SIZE_BYTES | |
| MAX_LITERAL_SIZE_WITHOUT_SIZE_BYTES | back to summary |
|---|---|
| private static final int MAX_LITERAL_SIZE_WITHOUT_SIZE_BYTES | |
| MAX_MATCH_LENGTH | back to summary |
|---|---|
| private static final int MAX_MATCH_LENGTH | |
| MAX_MATCH_LENGTH_WITH_ONE_OFFSET_BYTE | back to summary |
|---|---|
| private static final int MAX_MATCH_LENGTH_WITH_ONE_OFFSET_BYTE | |
| MAX_OFFSET_WITH_ONE_OFFSET_BYTE | back to summary |
|---|---|
| private static final int MAX_OFFSET_WITH_ONE_OFFSET_BYTE | |
| MAX_OFFSET_WITH_TWO_OFFSET_BYTES | back to summary |
|---|---|
| private static final int MAX_OFFSET_WITH_TWO_OFFSET_BYTES | |
| MIN_MATCH_LENGTH | back to summary |
|---|---|
| private static final int MIN_MATCH_LENGTH | |
| MIN_MATCH_LENGTH_WITH_ONE_OFFSET_BYTE | back to summary |
|---|---|
| private static final int MIN_MATCH_LENGTH_WITH_ONE_OFFSET_BYTE | |
| ONE_BYTE_COPY_TAG | back to summary |
|---|---|
| private static final int ONE_BYTE_COPY_TAG | |
| ONE_SIZE_BYTE_MARKER | back to summary |
|---|---|
| private static final int ONE_SIZE_BYTE_MARKER | |
| oneByte | back to summary |
|---|---|
| private final byte[] oneByte | |
| os | back to summary |
|---|---|
| private final OutputStream os | |
| THREE_SIZE_BYTE_MARKER | back to summary |
|---|---|
| private static final int THREE_SIZE_BYTE_MARKER | |
| TWO_BYTE_COPY_TAG | back to summary |
|---|---|
| private static final int TWO_BYTE_COPY_TAG | |
| TWO_SIZE_BYTE_MARKER | back to summary |
|---|---|
| private static final int TWO_SIZE_BYTE_MARKER | |
| SnappyCompressorOutputStream | back to summary |
|---|---|
| public SnappyCompressorOutputStream(final OutputStream os, final long uncompressedSize) throws IOException Constructor using the default block size of 32k.
| |
| SnappyCompressorOutputStream | back to summary |
|---|---|
| public SnappyCompressorOutputStream(final OutputStream os, final long uncompressedSize, final int blockSize) throws IOException Constructor using a configurable block size.
| |
| SnappyCompressorOutputStream | back to summary |
|---|---|
| public SnappyCompressorOutputStream(final OutputStream os, final long uncompressedSize, final Parameters params) throws IOException Constructor providing full control over the underlying LZ77 compressor.
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Doc from java. Closes this output stream and releases any system resources
associated with this stream. The general contract of
| |
| createParameterBuilder | back to summary |
|---|---|
| public static Parameters. Returns a builder correctly configured for the Snappy algorithm using the gven block size.
| |
| finish | back to summary |
|---|---|
| public void finish() throws IOException Compresses all remaining data and writes it to the stream, doesn't close the underlying stream.
| |
| write | back to summary |
|---|---|
| public void write(final byte[] data, final int off, final int len) throws IOException Overrides java. Doc from java. Writes
If
If
| |
| write | back to summary |
|---|---|
| public void write(final int b) throws IOException Implements abstract java. Doc from java. Writes the specified byte to this output stream. The general
contract for
| |
| writeBackReference | back to summary |
|---|---|
| private void writeBackReference(final LZ77Compressor. | |
| writeBackReferenceWithFourOffsetBytes | back to summary |
|---|---|
| private void writeBackReferenceWithFourOffsetBytes(final int len, final int offset) throws IOException | |
| writeBackReferenceWithLittleEndianOffset | back to summary |
|---|---|
| private void writeBackReferenceWithLittleEndianOffset(final int tag, final int offsetBytes, final int len, final int offset) throws IOException | |
| writeBackReferenceWithOneOffsetByte | back to summary |
|---|---|
| private void writeBackReferenceWithOneOffsetByte(final int len, final int offset) throws IOException | |
| writeBackReferenceWithTwoOffsetBytes | back to summary |
|---|---|
| private void writeBackReferenceWithTwoOffsetBytes(final int len, final int offset) throws IOException | |
| writeLiteralBlock | back to summary |
|---|---|
| private void writeLiteralBlock(final LZ77Compressor. | |
| writeLiteralBlockFourSizeBytes | back to summary |
|---|---|
| private void writeLiteralBlockFourSizeBytes(final LZ77Compressor. | |
| writeLiteralBlockNoSizeBytes | back to summary |
|---|---|
| private void writeLiteralBlockNoSizeBytes(final LZ77Compressor. | |
| writeLiteralBlockOneSizeByte | back to summary |
|---|---|
| private void writeLiteralBlockOneSizeByte(final LZ77Compressor. | |
| writeLiteralBlockThreeSizeBytes | back to summary |
|---|---|
| private void writeLiteralBlockThreeSizeBytes(final LZ77Compressor. | |
| writeLiteralBlockTwoSizeBytes | back to summary |
|---|---|
| private void writeLiteralBlockTwoSizeBytes(final LZ77Compressor. | |
| writeLiteralBlockWithSize | back to summary |
|---|---|
| private void writeLiteralBlockWithSize(final int tagByte, final int sizeBytes, final int len, final LZ77Compressor. | |
| writeLittleEndian | back to summary |
|---|---|
| private void writeLittleEndian(final int numBytes, final int num) throws IOException | |
| writeUncompressedSize | back to summary |
|---|---|
| private void writeUncompressedSize(long uncompressedSize) throws IOException | |