public final class SnappyFramedOutputStream
extends java.io.OutputStream
implements java.nio.channels.WritableByteChannel
| Modifier and Type | Field and Description |
|---|---|
private java.nio.ByteBuffer |
buffer |
private boolean |
closed |
static int |
DEFAULT_BLOCK_SIZE
The default block size to use.
|
static double |
DEFAULT_MIN_COMPRESSION_RATIO
The default min compression ratio to use.
|
private java.nio.ByteBuffer |
directInputBuffer |
private java.nio.ByteBuffer |
headerBuffer |
static int |
MAX_BLOCK_SIZE
The x-snappy-framed specification allows for a chunk size up to
16,777,211 bytes in length.
|
private double |
minCompressionRatio |
private java.nio.channels.WritableByteChannel |
out |
private java.nio.ByteBuffer |
outputBuffer |
| Constructor and Description |
|---|
SnappyFramedOutputStream(java.io.OutputStream out)
Creates a new
SnappyFramedOutputStream using the DEFAULT_BLOCK_SIZE
and DEFAULT_MIN_COMPRESSION_RATIO. |
SnappyFramedOutputStream(java.io.OutputStream out,
int blockSize,
double minCompressionRatio)
Creates a new
SnappyFramedOutputStream instance. |
SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out)
Creates a new
SnappyFramedOutputStream using the
DEFAULT_BLOCK_SIZE and DEFAULT_MIN_COMPRESSION_RATIO. |
SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out,
int blockSize,
double minCompressionRatio)
Creates a new
SnappyFramedOutputStream instance. |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
flush() |
private void |
flushBuffer()
Compresses and writes out any buffered data.
|
boolean |
isOpen() |
long |
transferFrom(java.io.InputStream is)
Transfers all the content from is to this
OutputStream. |
long |
transferFrom(java.nio.channels.ReadableByteChannel rbc)
Transfers all the content from rbc to this
WritableByteChannel. |
void |
write(byte[] input,
int offset,
int length) |
int |
write(java.nio.ByteBuffer src) |
void |
write(int b) |
private void |
writeBlock(java.nio.channels.WritableByteChannel out,
java.nio.ByteBuffer data,
boolean compressed,
int crc32c)
Write a frame (block) to out.
|
private void |
writeCompressed(java.nio.ByteBuffer buffer)
SnappyFramed.maskedCrc32c(byte[], int, int) the crc, compresses
the data, determines if the compression ratio is acceptable and calls
writeBlock(java.nio.channels.WritableByteChannel, java.nio.ByteBuffer, boolean, int) to
actually write the frame. |
private void |
writeHeader(java.nio.channels.WritableByteChannel out)
Writes the implementation specific header or "marker bytes" to
out.
|
public static final int MAX_BLOCK_SIZE
We place an additional restriction that the uncompressed data in a chunk
must be no longer than 65536 bytes. This allows consumers to easily use
small fixed-size buffers.
public static final int DEFAULT_BLOCK_SIZE
public static final double DEFAULT_MIN_COMPRESSION_RATIO
private final java.nio.ByteBuffer headerBuffer
private final java.nio.ByteBuffer buffer
private final java.nio.ByteBuffer directInputBuffer
private final java.nio.ByteBuffer outputBuffer
private final double minCompressionRatio
private final java.nio.channels.WritableByteChannel out
private boolean closed
public SnappyFramedOutputStream(java.io.OutputStream out)
throws java.io.IOException
SnappyFramedOutputStream using the DEFAULT_BLOCK_SIZE
and DEFAULT_MIN_COMPRESSION_RATIO.out - The underlying OutputStream to write to. Must not be
null.java.io.IOExceptionpublic SnappyFramedOutputStream(java.io.OutputStream out,
int blockSize,
double minCompressionRatio)
throws java.io.IOException
SnappyFramedOutputStream instance.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. Must be in (0, 65536].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.IOExceptionpublic SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out)
throws java.io.IOException
SnappyFramedOutputStream using the
DEFAULT_BLOCK_SIZE and DEFAULT_MIN_COMPRESSION_RATIO.out - The underlying WritableByteChannel to write to. Must
not be null.java.io.IOExceptionpublic SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out,
int blockSize,
double minCompressionRatio)
throws java.io.IOException
SnappyFramedOutputStream instance.out - The underlying WritableByteChannel to write to. Must
not be null.blockSize - The block size (of raw data) to compress before writing frames
to out. Must be in (0, 65536].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.IOExceptionprivate void writeHeader(java.nio.channels.WritableByteChannel out)
throws java.io.IOException
out - The underlying OutputStream.java.io.IOExceptionpublic boolean isOpen()
isOpen in interface java.nio.channels.Channelpublic void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionpublic void write(byte[] input,
int offset,
int length)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionpublic int write(java.nio.ByteBuffer src)
throws java.io.IOException
write in interface java.nio.channels.WritableByteChanneljava.io.IOExceptionpublic long transferFrom(java.io.InputStream is)
throws java.io.IOException
OutputStream.
This potentially limits the amount of buffering required to compress
content.is - The source of data to compress.java.io.IOExceptionpublic long transferFrom(java.nio.channels.ReadableByteChannel rbc)
throws java.io.IOException
WritableByteChannel. This potentially limits the amount of
buffering required to compress content.rbc - The source of data to compress.java.io.IOExceptionpublic final void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.OutputStreamjava.io.IOExceptionpublic final void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in interface java.nio.channels.Channelclose in class java.io.OutputStreamjava.io.IOExceptionprivate void flushBuffer()
throws java.io.IOException
java.io.IOExceptionprivate void writeCompressed(java.nio.ByteBuffer buffer)
throws java.io.IOException
SnappyFramed.maskedCrc32c(byte[], int, int) the crc, compresses
the data, determines if the compression ratio is acceptable and calls
writeBlock(java.nio.channels.WritableByteChannel, java.nio.ByteBuffer, boolean, int) to
actually write the frame.buffer - java.io.IOExceptionprivate void writeBlock(java.nio.channels.WritableByteChannel out,
java.nio.ByteBuffer data,
boolean compressed,
int crc32c)
throws java.io.IOException
out - The OutputStream to write to.data - The data to write.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