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 int
DEFAULT_BLOCK_SIZE
The default block size to use.static double
DEFAULT_MIN_COMPRESSION_RATIO
The default min compression ratio to use.static int
MAX_BLOCK_SIZE
The 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 newSnappyFramedOutputStream
using theDEFAULT_BLOCK_SIZE
andDEFAULT_MIN_COMPRESSION_RATIO
.SnappyFramedOutputStream(java.io.OutputStream out, int blockSize, double minCompressionRatio)
Creates a newSnappyFramedOutputStream
instance.SnappyFramedOutputStream(java.io.OutputStream out, int blockSize, double minCompressionRatio, BufferPool bufferPool)
Creates a newSnappyFramedOutputStream
instance.SnappyFramedOutputStream(java.io.OutputStream out, BufferPool bufferPool)
Creates a newSnappyFramedOutputStream
using theDEFAULT_BLOCK_SIZE
andDEFAULT_MIN_COMPRESSION_RATIO
.SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out)
Creates a newSnappyFramedOutputStream
using theDEFAULT_BLOCK_SIZE
andDEFAULT_MIN_COMPRESSION_RATIO
.SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out, int blockSize, double minCompressionRatio)
Creates a newSnappyFramedOutputStream
instance.SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out, int blockSize, double minCompressionRatio, BufferPool bufferPool)
Creates a newSnappyFramedOutputStream
instance.SnappyFramedOutputStream(java.nio.channels.WritableByteChannel out, BufferPool bufferPool)
Creates a newSnappyFramedOutputStream
using theDEFAULT_BLOCK_SIZE
andDEFAULT_MIN_COMPRESSION_RATIO
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
flush()
boolean
isOpen()
long
transferFrom(java.io.InputStream is)
Transfers all the content from is to thisOutputStream
.long
transferFrom(java.nio.channels.ReadableByteChannel rbc)
Transfers all the content from rbc to thisWritableByteChannel
.void
write(byte[] input, int offset, int length)
void
write(int b)
int
write(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.IOException
Creates a newSnappyFramedOutputStream
using theDEFAULT_BLOCK_SIZE
andDEFAULT_MIN_COMPRESSION_RATIO
.Uses
DefaultPoolFactory
to obtainBufferPool
for buffers.- Parameters:
out
- The underlyingOutputStream
to write to. Must not benull
.- Throws:
java.io.IOException
-
SnappyFramedOutputStream
public SnappyFramedOutputStream(java.io.OutputStream out, BufferPool bufferPool) throws java.io.IOException
Creates a newSnappyFramedOutputStream
using theDEFAULT_BLOCK_SIZE
andDEFAULT_MIN_COMPRESSION_RATIO
.- Parameters:
out
- The underlyingOutputStream
to 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.IOException
Creates a newSnappyFramedOutputStream
instance.Uses
DefaultPoolFactory
to obtainBufferPool
for buffers.- Parameters:
out
- The underlyingOutputStream
to 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.IOException
Creates a newSnappyFramedOutputStream
instance.- Parameters:
out
- The underlyingOutputStream
to 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.IOException
Creates a newSnappyFramedOutputStream
using theDEFAULT_BLOCK_SIZE
andDEFAULT_MIN_COMPRESSION_RATIO
.Uses
DefaultPoolFactory
to obtainBufferPool
for buffers.- Parameters:
out
- The underlyingWritableByteChannel
to 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.IOException
Creates a newSnappyFramedOutputStream
using theDEFAULT_BLOCK_SIZE
andDEFAULT_MIN_COMPRESSION_RATIO
.Uses
DefaultPoolFactory
to obtainBufferPool
for buffers.- Parameters:
out
- The underlyingWritableByteChannel
to 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.IOException
Creates a newSnappyFramedOutputStream
instance.- Parameters:
out
- The underlyingWritableByteChannel
to 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.IOException
Creates a newSnappyFramedOutputStream
instance.- Parameters:
out
- The underlyingWritableByteChannel
to 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:
isOpen
in interfacejava.nio.channels.Channel
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] input, int offset, int length) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer src) throws java.io.IOException
- Specified by:
write
in interfacejava.nio.channels.WritableByteChannel
- Throws:
java.io.IOException
-
transferFrom
public long transferFrom(java.io.InputStream is) throws java.io.IOException
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:
java.io.IOException
- Since:
- 1.1.1
-
transferFrom
public long transferFrom(java.nio.channels.ReadableByteChannel rbc) throws java.io.IOException
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:
java.io.IOException
- Since:
- 1.1.1
-
flush
public final void flush() throws java.io.IOException
- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
close
public final void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.nio.channels.Channel
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
-