Package org.iq80.snappy
Class SnappyOutputStream
java.lang.Object
java.io.OutputStream
org.iq80.snappy.AbstractSnappyOutputStream
org.iq80.snappy.SnappyOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
Deprecated.
This class implements an output stream for writing Snappy compressed data.
The output format is the stream header "snappy\0" followed by one or more
compressed blocks of data, each of which is preceded by a seven byte header.
The first byte of the header is a flag indicating if the block is compressed
or not. A value of 0x00 means uncompressed, and 0x01 means compressed.
The second and third bytes are the size of the block in the stream as a big
endian number. This value is never zero as empty blocks are never written.
The maximum allowed length is 32k (1 invalid input: '<'invalid input: '<' 15).
The remaining four byes are crc32c checksum of the user input data masked
with the following function:
((crc >>> 15) | (crc << 17)) + 0xa282ead8
An uncompressed block is simply copied from the input, thus guaranteeing
that the output is never larger than the input (not including the header).
NOTE:This data produced by this class is not compatible with the
x-snappy-framed specification. It can only be read by
SnappyInputStream.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanDeprecated.(package private) static final intDeprecated.static final doubleDeprecated.Write out the uncompressed content if the compression ratio (compressed length / raw length) exceeds this value.(package private) static final byte[]Deprecated. -
Constructor Summary
ConstructorsModifierConstructorDescriptionDeprecated.Creates a Snappy output stream to write data to the specified underlying output stream.privateSnappyOutputStream(OutputStream out, boolean calculateChecksum) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionprotected intcalculateCRC32C(byte[] data, int offset, int length) Deprecated.Calculates a CRC32C checksum over the data.static SnappyOutputStreamDeprecated.Creates a Snappy output stream with block checksums disabled.protected voidwriteBlock(OutputStream out, byte[] data, int offset, int length, boolean compressed, int crc32c) Deprecated.Write a frame (block) to out.protected voidwriteHeader(OutputStream out) Deprecated.Writes the implementation specific header or "marker bytes" to out.Methods inherited from class org.iq80.snappy.AbstractSnappyOutputStream
close, flush, write, writeMethods inherited from class java.io.OutputStream
nullOutputStream, write
-
Field Details
-
STREAM_HEADER
static final byte[] STREAM_HEADERDeprecated. -
MAX_BLOCK_SIZE
static final int MAX_BLOCK_SIZEDeprecated.- See Also:
-
MIN_COMPRESSION_RATIO
public static final double MIN_COMPRESSION_RATIODeprecated.Write out the uncompressed content if the compression ratio (compressed length / raw length) exceeds this value.- See Also:
-
calculateChecksum
private final boolean calculateChecksumDeprecated.
-
-
Constructor Details
-
SnappyOutputStream
Deprecated.Creates a Snappy output stream to write data to the specified underlying output stream.- Parameters:
out- the underlying output stream- Throws:
IOException
-
SnappyOutputStream
Deprecated.- Throws:
IOException
-
-
Method Details
-
newChecksumFreeBenchmarkOutputStream
public static SnappyOutputStream newChecksumFreeBenchmarkOutputStream(OutputStream out) throws IOException Deprecated.Creates a Snappy output stream with block checksums disabled. This is only useful for apples-to-apples benchmarks with other compressors that do not perform block checksums.- Parameters:
out- the underlying output stream- Throws:
IOException
-
writeHeader
Deprecated.Description copied from class:AbstractSnappyOutputStreamWrites the implementation specific header or "marker bytes" to out.- Specified by:
writeHeaderin classAbstractSnappyOutputStream- Parameters:
out- The underlyingOutputStream.- Throws:
IOException
-
calculateCRC32C
protected int calculateCRC32C(byte[] data, int offset, int length) Deprecated.Description copied from class:AbstractSnappyOutputStreamCalculates a CRC32C checksum over the data.This can be overridden to provider alternative implementations (such as returning 0 if checksums are not desired).
- Overrides:
calculateCRC32Cin classAbstractSnappyOutputStream- Returns:
- The CRC32 checksum.
-
writeBlock
protected void writeBlock(OutputStream out, byte[] data, int offset, int length, boolean compressed, int crc32c) throws IOException Deprecated.Description copied from class:AbstractSnappyOutputStreamWrite a frame (block) to out.- Specified by:
writeBlockin classAbstractSnappyOutputStream- Parameters:
out- TheOutputStreamto write to.data- The data to write.offset- The offset in data to start at.length- The length of data to use.compressed- Indicates if data is the compressed or raw content. This is based on whether the compression ratio desired is reached.crc32c- The calculated checksum.- Throws:
IOException
-
SnappyFramedOutputStreamwhich implements the standardx-snappy-framedspecification.