Class SnappyFramedOutputStream
java.lang.Object
java.io.OutputStream
org.xerial.snappy.SnappyFramedOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, Channel, WritableByteChannel
- Since:
- 1.1.0
- Author:
- Brett Okken
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default block size to use.static final doubleThe default min compression ratio to use.static final intThe x-snappy-framed specification allows for a chunk size up to 16,777,211 bytes in length. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newSnappyFramedOutputStreamusing theDEFAULT_BLOCK_SIZEandDEFAULT_MIN_COMPRESSION_RATIO.SnappyFramedOutputStream(OutputStream out, int blockSize, double minCompressionRatio) Creates a newSnappyFramedOutputStreaminstance.SnappyFramedOutputStream(OutputStream out, int blockSize, double minCompressionRatio, BufferPool bufferPool) Creates a newSnappyFramedOutputStreaminstance.SnappyFramedOutputStream(OutputStream out, BufferPool bufferPool) Creates a newSnappyFramedOutputStreamusing theDEFAULT_BLOCK_SIZEandDEFAULT_MIN_COMPRESSION_RATIO.Creates a newSnappyFramedOutputStreamusing theDEFAULT_BLOCK_SIZEandDEFAULT_MIN_COMPRESSION_RATIO.SnappyFramedOutputStream(WritableByteChannel out, int blockSize, double minCompressionRatio) Creates a newSnappyFramedOutputStreaminstance.SnappyFramedOutputStream(WritableByteChannel out, int blockSize, double minCompressionRatio, BufferPool bufferPool) Creates a newSnappyFramedOutputStreaminstance.SnappyFramedOutputStream(WritableByteChannel out, BufferPool bufferPool) Creates a newSnappyFramedOutputStreamusing theDEFAULT_BLOCK_SIZEandDEFAULT_MIN_COMPRESSION_RATIO. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclose()final voidflush()booleanisOpen()longTransfers all the content from is to thisOutputStream.longTransfers all the content from rbc to thisWritableByteChannel.voidwrite(byte[] input, int offset, int length) voidwrite(int b) intwrite(ByteBuffer src) Methods inherited from class OutputStream
nullOutputStream, write
-
Field Details
-
MAX_BLOCK_SIZE
public static final int MAX_BLOCK_SIZEThe x-snappy-framed specification allows for a chunk size up to 16,777,211 bytes in length. However, it also goes on to state: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.- See Also:
-
DEFAULT_BLOCK_SIZE
public static final int DEFAULT_BLOCK_SIZEThe default block size to use.- See Also:
-
DEFAULT_MIN_COMPRESSION_RATIO
public static final double DEFAULT_MIN_COMPRESSION_RATIOThe default min compression ratio to use.- See Also:
-
-
Constructor Details
-
SnappyFramedOutputStream
Creates a newSnappyFramedOutputStreamusing theDEFAULT_BLOCK_SIZEandDEFAULT_MIN_COMPRESSION_RATIO.Uses
DefaultPoolFactoryto obtainBufferPoolfor buffers.- Parameters:
out- The underlyingOutputStreamto write to. Must not benull.- Throws:
IOException
-
SnappyFramedOutputStream
Creates a newSnappyFramedOutputStreamusing theDEFAULT_BLOCK_SIZEandDEFAULT_MIN_COMPRESSION_RATIO.- Parameters:
out- The underlyingOutputStreamto write to. Must not benull.bufferPool- Used to obtain buffer instances. Must not benull.- Throws:
IOException
-
SnappyFramedOutputStream
public SnappyFramedOutputStream(OutputStream out, int blockSize, double minCompressionRatio) throws IOException Creates a newSnappyFramedOutputStreaminstance.Uses
DefaultPoolFactoryto obtainBufferPoolfor buffers.- Parameters:
out- The underlyingOutputStreamto write to. Must not benull.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].- Throws:
IOException
-
SnappyFramedOutputStream
public SnappyFramedOutputStream(OutputStream out, int blockSize, double minCompressionRatio, BufferPool bufferPool) throws IOException Creates a newSnappyFramedOutputStreaminstance.- Parameters:
out- The underlyingOutputStreamto write to. Must not benull.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].bufferPool- Used to obtain buffer instances. Must not benull.- Throws:
IOException
-
SnappyFramedOutputStream
Creates a newSnappyFramedOutputStreamusing theDEFAULT_BLOCK_SIZEandDEFAULT_MIN_COMPRESSION_RATIO.Uses
DefaultPoolFactoryto obtainBufferPoolfor buffers.- Parameters:
out- The underlyingWritableByteChannelto write to. Must not benull.- Throws:
IOException- Since:
- 1.1.1
-
SnappyFramedOutputStream
Creates a newSnappyFramedOutputStreamusing theDEFAULT_BLOCK_SIZEandDEFAULT_MIN_COMPRESSION_RATIO.Uses
DefaultPoolFactoryto obtainBufferPoolfor buffers.- Parameters:
out- The underlyingWritableByteChannelto write to. Must not benull.bufferPool- Used to obtain buffer instances. Must not benull.- Throws:
IOException
-
SnappyFramedOutputStream
public SnappyFramedOutputStream(WritableByteChannel out, int blockSize, double minCompressionRatio) throws IOException Creates a newSnappyFramedOutputStreaminstance.- Parameters:
out- The underlyingWritableByteChannelto write to. Must not benull.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].- Throws:
IOException- Since:
- 1.1.1
-
SnappyFramedOutputStream
public SnappyFramedOutputStream(WritableByteChannel out, int blockSize, double minCompressionRatio, BufferPool bufferPool) throws IOException Creates a newSnappyFramedOutputStreaminstance.- Parameters:
out- The underlyingWritableByteChannelto write to. Must not benull.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].bufferPool- Used to obtain buffer instances. Must not benull.- Throws:
IOException- Since:
- 1.1.1
-
-
Method Details
-
isOpen
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Specified by:
writein interfaceWritableByteChannel- Throws:
IOException
-
transferFrom
Transfers all the content from is to thisOutputStream. This potentially limits the amount of buffering required to compress content.- Parameters:
is- The source of data to compress.- Returns:
- The number of bytes read from is.
- Throws:
IOException- Since:
- 1.1.1
-
transferFrom
Transfers all the content from rbc to thisWritableByteChannel. This potentially limits the amount of buffering required to compress content.- Parameters:
rbc- The source of data to compress.- Returns:
- The number of bytes read from rbc.
- Throws:
IOException- Since:
- 1.1.1
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-