Package org.xerial.snappy
Class SnappyFramedOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.xerial.snappy.SnappyFramedOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable,java.nio.channels.Channel,java.nio.channels.WritableByteChannel
public final class SnappyFramedOutputStream extends java.io.OutputStream implements java.nio.channels.WritableByteChannel- Since:
- 1.1.0
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BLOCK_SIZEThe default block size to use.static doubleDEFAULT_MIN_COMPRESSION_RATIOThe default min compression ratio to use.static intMAX_BLOCK_SIZEThe x-snappy-framed specification allows for a chunk size up to 16,777,211 bytes in length.
-
Constructor Summary
Constructors Constructor Description SnappyFramedOutputStream(java.io.OutputStream out)Creates a newSnappyFramedOutputStreamusing theDEFAULT_BLOCK_SIZEandDEFAULT_MIN_COMPRESSION_RATIO.SnappyFramedOutputStream(java.io.OutputStream out, int blockSize, double minCompressionRatio)Creates a newSnappyFramedOutputStreaminstance.SnappyFramedOutputStream(java.io.OutputStream out, int blockSize, double minCompressionRatio, BufferPool bufferPool)Creates a newSnappyFramedOutputStreaminstance.SnappyFramedOutputStream(java.io.OutputStream out, BufferPool bufferPool)Creates a newSnappyFramedOutputStreamusing theDEFAULT_BLOCK_SIZEandDEFAULT_MIN_COMPRESSION_RATIO.SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out)Creates a newSnappyFramedOutputStreamusing theDEFAULT_BLOCK_SIZEandDEFAULT_MIN_COMPRESSION_RATIO.SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out, int blockSize, double minCompressionRatio)Creates a newSnappyFramedOutputStreaminstance.SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out, int blockSize, double minCompressionRatio, BufferPool bufferPool)Creates a newSnappyFramedOutputStreaminstance.SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out, BufferPool bufferPool)Creates a newSnappyFramedOutputStreamusing theDEFAULT_BLOCK_SIZEandDEFAULT_MIN_COMPRESSION_RATIO.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()booleanisOpen()longtransferFrom(java.io.InputStream is)Transfers all the content from is to thisOutputStream.longtransferFrom(java.nio.channels.ReadableByteChannel rbc)Transfers all the content from rbc to thisWritableByteChannel.voidwrite(byte[] input, int offset, int length)voidwrite(int b)intwrite(java.nio.ByteBuffer src)
-
-
-
Field Detail
-
MAX_BLOCK_SIZE
public static final int MAX_BLOCK_SIZE
The 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:
- Constant Field Values
-
DEFAULT_BLOCK_SIZE
public static final int DEFAULT_BLOCK_SIZE
The default block size to use.- See Also:
- Constant Field Values
-
DEFAULT_MIN_COMPRESSION_RATIO
public static final double DEFAULT_MIN_COMPRESSION_RATIO
The default min compression ratio to use.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SnappyFramedOutputStream
public SnappyFramedOutputStream(java.io.OutputStream out) throws java.io.IOExceptionCreates a newSnappyFramedOutputStreamusing theDEFAULT_BLOCK_SIZEandDEFAULT_MIN_COMPRESSION_RATIO.Uses
DefaultPoolFactoryto obtainBufferPoolfor buffers.- Parameters:
out- The underlyingOutputStreamto write to. Must not benull.- Throws:
java.io.IOException
-
SnappyFramedOutputStream
public SnappyFramedOutputStream(java.io.OutputStream out, BufferPool bufferPool) throws java.io.IOExceptionCreates 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:
java.io.IOException
-
SnappyFramedOutputStream
public SnappyFramedOutputStream(java.io.OutputStream out, int blockSize, double minCompressionRatio) throws java.io.IOExceptionCreates 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:
java.io.IOException
-
SnappyFramedOutputStream
public SnappyFramedOutputStream(java.io.OutputStream out, int blockSize, double minCompressionRatio, BufferPool bufferPool) throws java.io.IOExceptionCreates 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:
java.io.IOException
-
SnappyFramedOutputStream
public SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out) throws java.io.IOExceptionCreates a newSnappyFramedOutputStreamusing theDEFAULT_BLOCK_SIZEandDEFAULT_MIN_COMPRESSION_RATIO.Uses
DefaultPoolFactoryto obtainBufferPoolfor buffers.- Parameters:
out- The underlyingWritableByteChannelto write to. Must not benull.- Throws:
java.io.IOException- Since:
- 1.1.1
-
SnappyFramedOutputStream
public SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out, BufferPool bufferPool) throws java.io.IOExceptionCreates 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:
java.io.IOException
-
SnappyFramedOutputStream
public SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out, int blockSize, double minCompressionRatio) throws java.io.IOExceptionCreates 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:
java.io.IOException- Since:
- 1.1.1
-
SnappyFramedOutputStream
public SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out, int blockSize, double minCompressionRatio, BufferPool bufferPool) throws java.io.IOExceptionCreates 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:
java.io.IOException- Since:
- 1.1.1
-
-
Method Detail
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacejava.nio.channels.Channel
-
write
public void write(int b) throws java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] input, int offset, int length) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer src) throws java.io.IOException- Specified by:
writein interfacejava.nio.channels.WritableByteChannel- Throws:
java.io.IOException
-
transferFrom
public long transferFrom(java.io.InputStream is) throws java.io.IOExceptionTransfers 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:
java.io.IOException- Since:
- 1.1.1
-
transferFrom
public long transferFrom(java.nio.channels.ReadableByteChannel rbc) throws java.io.IOExceptionTransfers 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:
java.io.IOException- Since:
- 1.1.1
-
flush
public final void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException
-
close
public final void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
-