Package org.xerial.snappy
Class SnappyFramedInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.xerial.snappy.SnappyFramedInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.Channel,java.nio.channels.ReadableByteChannel
public final class SnappyFramedInputStream extends java.io.InputStream implements java.nio.channels.ReadableByteChannel- Since:
- 1.1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classSnappyFramedInputStream.FrameActionstatic classSnappyFramedInputStream.FrameDatastatic classSnappyFramedInputStream.FrameMetaData
-
Field Summary
Fields Modifier and Type Field Description private byte[]bufferBuffer contains a copy of the uncompressed data for the block.private BufferPoolbufferPoolprivate booleanclosedIndicates if this instance has been closed.private java.util.zip.Checksumcrc32private booleaneofIndicates if we have reached the EOF oninput.private java.nio.ByteBufferframeHeaderprivate java.nio.ByteBufferinputA single frame read from the underlyingInputStream.private intpositionThe next position to read frombuffer.private java.nio.channels.ReadableByteChannelrbcprivate java.nio.ByteBufferuncompressedDirectThe decompressed data frominput.private intvalidThe position ininputbuffer to read to.private booleanverifyChecksums
-
Constructor Summary
Constructors Constructor Description SnappyFramedInputStream(java.io.InputStream in)Creates a Snappy input stream to read data from the specified underlying input stream.SnappyFramedInputStream(java.io.InputStream in, boolean verifyChecksums)Creates a Snappy input stream to read data from the specified underlying input stream.SnappyFramedInputStream(java.io.InputStream in, boolean verifyChecksums, BufferPool bufferPool)Creates a Snappy input stream to read data from the specified underlying input stream.SnappyFramedInputStream(java.io.InputStream in, BufferPool bufferPool)Creates a Snappy input stream to read data from the specified underlying input stream.SnappyFramedInputStream(java.nio.channels.ReadableByteChannel in)Creates a Snappy input stream to read data from the specified underlying channel.SnappyFramedInputStream(java.nio.channels.ReadableByteChannel in, boolean verifyChecksums)Creates a Snappy input stream to read data from the specified underlying channel.SnappyFramedInputStream(java.nio.channels.ReadableByteChannel in, boolean verifyChecksums, BufferPool bufferPool)Creates a Snappy input stream to read data from the specified underlying channel.SnappyFramedInputStream(java.nio.channels.ReadableByteChannel in, BufferPool bufferPool)Creates a Snappy input stream to read data from the specified underlying channel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidallocateBuffersBasedOnSize(int size)intavailable()voidclose()private booleanensureBuffer()private SnappyFramedInputStream.FrameDatagetFrameData(java.nio.ByteBuffer content)private SnappyFramedInputStream.FrameMetaDatagetFrameMetaData(java.nio.ByteBuffer frameHeader)booleanisOpen()intread()intread(byte[] output, int offset, int length)intread(java.nio.ByteBuffer dst)private booleanreadBlockHeader()longtransferTo(java.io.OutputStream os)Transfers the entire content of thisInputStreamto os.longtransferTo(java.nio.channels.WritableByteChannel wbc)Transfers the entire content of thisReadableByteChannelto wbc.
-
-
-
Field Detail
-
crc32
private final java.util.zip.Checksum crc32
-
rbc
private final java.nio.channels.ReadableByteChannel rbc
-
frameHeader
private final java.nio.ByteBuffer frameHeader
-
verifyChecksums
private final boolean verifyChecksums
-
bufferPool
private final BufferPool bufferPool
-
input
private java.nio.ByteBuffer input
A single frame read from the underlyingInputStream.
-
uncompressedDirect
private java.nio.ByteBuffer uncompressedDirect
The decompressed data frominput.
-
closed
private boolean closed
Indicates if this instance has been closed.
-
eof
private boolean eof
Indicates if we have reached the EOF oninput.
-
valid
private int valid
The position ininputbuffer to read to.
-
position
private int position
The next position to read frombuffer.
-
buffer
private byte[] buffer
Buffer contains a copy of the uncompressed data for the block.
-
-
Constructor Detail
-
SnappyFramedInputStream
public SnappyFramedInputStream(java.io.InputStream in) throws java.io.IOExceptionCreates a Snappy input stream to read data from the specified underlying input stream.Uses
DefaultPoolFactoryto obtainBufferPoolfor buffers.- Parameters:
in- the underlying input stream. Must not benull.- Throws:
java.io.IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(java.io.InputStream in, BufferPool bufferPool) throws java.io.IOExceptionCreates a Snappy input stream to read data from the specified underlying input stream.- Parameters:
in- the underlying input stream. Must not benull.bufferPool- Used to obtain buffer instances. Must not benull.- Throws:
java.io.IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(java.io.InputStream in, boolean verifyChecksums) throws java.io.IOExceptionCreates a Snappy input stream to read data from the specified underlying input stream.Uses
DefaultPoolFactoryto obtainBufferPoolfor buffers.- Parameters:
in- the underlying input stream. Must not benull.verifyChecksums- if true, checksums in input stream will be verified- Throws:
java.io.IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(java.io.InputStream in, boolean verifyChecksums, BufferPool bufferPool) throws java.io.IOExceptionCreates a Snappy input stream to read data from the specified underlying input stream.- Parameters:
in- the underlying input stream. Must not benull.verifyChecksums- if true, checksums in input stream will be verifiedbufferPool- Used to obtain buffer instances. Must not benull.- Throws:
java.io.IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(java.nio.channels.ReadableByteChannel in, BufferPool bufferPool) throws java.io.IOExceptionCreates a Snappy input stream to read data from the specified underlying channel.- Parameters:
in- the underlying readable channel. Must not benull.bufferPool- Used to obtain buffer instances. Must not benull.- Throws:
java.io.IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(java.nio.channels.ReadableByteChannel in) throws java.io.IOExceptionCreates a Snappy input stream to read data from the specified underlying channel.Uses
DefaultPoolFactoryto obtainBufferPoolfor buffers.- Parameters:
in- the underlying readable channel. Must not benull.- Throws:
java.io.IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(java.nio.channels.ReadableByteChannel in, boolean verifyChecksums) throws java.io.IOExceptionCreates a Snappy input stream to read data from the specified underlying channel.Uses
DefaultPoolFactoryto obtainBufferPoolfor buffers.- Parameters:
in- the underlying readable channel. Must not benull.verifyChecksums- if true, checksums in input stream will be verified- Throws:
java.io.IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(java.nio.channels.ReadableByteChannel in, boolean verifyChecksums, BufferPool bufferPool) throws java.io.IOExceptionCreates a Snappy input stream to read data from the specified underlying channel.- Parameters:
in- the underlying readable channel. Must not benull.verifyChecksums- if true, checksums in input stream will be verifiedbufferPool- Used to obtain buffer instances. Must not benull.- Throws:
java.io.IOException
-
-
Method Detail
-
allocateBuffersBasedOnSize
private void allocateBuffersBasedOnSize(int size)
- Parameters:
size-
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] output, int offset, int length) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException- Overrides:
availablein classjava.io.InputStream- Throws:
java.io.IOException
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacejava.nio.channels.Channel
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOException- Specified by:
readin interfacejava.nio.channels.ReadableByteChannel- Throws:
java.io.IOException
-
transferTo
public long transferTo(java.io.OutputStream os) throws java.io.IOExceptionTransfers the entire content of thisInputStreamto os. This potentially limits the amount of buffering required to decompress content.Unlike
read(byte[], int, int), this method does not need to be called multiple times. A single call will transfer all available content. Any calls after the source has been exhausted will result in a return value of0.- Overrides:
transferToin classjava.io.InputStream- Parameters:
os- The destination to write decompressed content to.- Returns:
- The number of bytes transferred.
- Throws:
java.io.IOException- Since:
- 1.1.1
-
transferTo
public long transferTo(java.nio.channels.WritableByteChannel wbc) throws java.io.IOExceptionTransfers the entire content of thisReadableByteChannelto wbc. This potentially limits the amount of buffering required to decompress content.Unlike
read(ByteBuffer), this method does not need to be called multiple times. A single call will transfer all available content. Any calls after the source has been exhausted will result in a return value of0.- Parameters:
wbc- The destination to write decompressed content to.- Returns:
- The number of bytes transferred.
- Throws:
java.io.IOException- Since:
- 1.1.1
-
close
public 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.InputStream- Throws:
java.io.IOException
-
ensureBuffer
private boolean ensureBuffer() throws java.io.IOException- Throws:
java.io.IOException
-
readBlockHeader
private boolean readBlockHeader() throws java.io.IOException- Throws:
java.io.IOException
-
getFrameMetaData
private SnappyFramedInputStream.FrameMetaData getFrameMetaData(java.nio.ByteBuffer frameHeader) throws java.io.IOException
- Parameters:
frameHeader-- Returns:
- Throws:
java.io.IOException
-
getFrameData
private SnappyFramedInputStream.FrameData getFrameData(java.nio.ByteBuffer content) throws java.io.IOException
- Parameters:
content-- Returns:
- Throws:
java.io.IOException
-
-