abstract class AbstractSnappyOutputStream
extends java.io.OutputStream
SnappyOutputStream
and
SnappyFramedOutputStream
.
Delegates writing the header bytes and individual frames to the specific implementations. Implementations may also override the crc32 checksum calculation.
Modifier and Type | Field and Description |
---|---|
private int |
blockSize |
private byte[] |
buffer |
private boolean |
closed |
private double |
minCompressionRatio |
private java.io.OutputStream |
out |
private byte[] |
outputBuffer |
private int |
position |
private BufferRecycler |
recycler |
Constructor and Description |
---|
AbstractSnappyOutputStream(java.io.OutputStream out,
int blockSize,
double minCompressionRatio) |
Modifier and Type | Method and Description |
---|---|
protected int |
calculateCRC32C(byte[] data,
int offset,
int length)
Calculates a CRC32C checksum over the data.
|
void |
close() |
private void |
copyToBuffer(byte[] input,
int offset,
int length) |
void |
flush() |
private void |
flushBuffer()
Compresses and writes out any buffered data.
|
void |
write(byte[] input,
int offset,
int length) |
void |
write(int b) |
protected abstract void |
writeBlock(java.io.OutputStream out,
byte[] data,
int offset,
int length,
boolean compressed,
int crc32c)
Write a frame (block) to out.
|
private void |
writeCompressed(byte[] input,
int offset,
int length)
Calculates the crc, compresses
the data, determines if the compression ratio is acceptable and calls
writeBlock(OutputStream, byte[], int, int, boolean, int) to
actually write the frame. |
protected abstract void |
writeHeader(java.io.OutputStream out)
Writes the implementation specific header or "marker bytes" to
out.
|
private final BufferRecycler recycler
private final int blockSize
private final byte[] buffer
private final byte[] outputBuffer
private final double minCompressionRatio
private final java.io.OutputStream out
private int position
private boolean closed
public AbstractSnappyOutputStream(java.io.OutputStream out, int blockSize, double minCompressionRatio) throws java.io.IOException
out
- The underlying OutputStream
to write to. Must not be null
.blockSize
- The block size (of raw data) to compress before writing frames to out.minCompressionRatio
- Defines the minimum compression ratio (compressedLength / rawLength
) that must be achieved to
write the compressed data. This must be in (0, 1.0].java.io.IOException
protected abstract void writeHeader(java.io.OutputStream out) throws java.io.IOException
out
- The underlying OutputStream
.java.io.IOException
public void write(int b) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public void write(byte[] input, int offset, int length) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public final void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
java.io.IOException
public final void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
java.io.IOException
private void copyToBuffer(byte[] input, int offset, int length)
private void flushBuffer() throws java.io.IOException
java.io.IOException
private void writeCompressed(byte[] input, int offset, int length) throws java.io.IOException
Calculates
the crc, compresses
the data, determines if the compression ratio is acceptable and calls
writeBlock(OutputStream, byte[], int, int, boolean, int)
to
actually write the frame.input
- The byte[] containing the raw data to be compressed.offset
- The offset into input where the data starts.length
- The amount of data in input.java.io.IOException
protected int calculateCRC32C(byte[] data, int offset, int length)
This can be overridden to provider alternative implementations (such as returning 0 if checksums are not desired).
protected abstract void writeBlock(java.io.OutputStream out, byte[] data, int offset, int length, boolean compressed, int crc32c) throws java.io.IOException
out
- The OutputStream
to 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.java.io.IOException