Class SnappyFramedInputStream
java.lang.Object
java.io.InputStream
org.xerial.snappy.SnappyFramedInputStream
- All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ReadableByteChannel
- Since:
- 1.1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enumstatic final classstatic final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]Buffer contains a copy of the uncompressed data for the block.private final BufferPoolprivate booleanIndicates if this instance has been closed.private final Checksumprivate booleanIndicates if we have reached the EOF oninput.private final ByteBufferprivate ByteBufferA single frame read from the underlyingInputStream.private intThe next position to read frombuffer.private final ReadableByteChannelprivate ByteBufferThe decompressed data frominput.private intThe position ininputbuffer to read to.private final boolean -
Constructor Summary
ConstructorsConstructorDescriptionCreates a Snappy input stream to read data from the specified underlying input stream.SnappyFramedInputStream(InputStream in, boolean verifyChecksums) Creates a Snappy input stream to read data from the specified underlying input stream.SnappyFramedInputStream(InputStream in, boolean verifyChecksums, BufferPool bufferPool) Creates a Snappy input stream to read data from the specified underlying input stream.SnappyFramedInputStream(InputStream in, BufferPool bufferPool) Creates a Snappy input stream to read data from the specified underlying input stream.Creates a Snappy input stream to read data from the specified underlying channel.SnappyFramedInputStream(ReadableByteChannel in, boolean verifyChecksums) Creates a Snappy input stream to read data from the specified underlying channel.SnappyFramedInputStream(ReadableByteChannel in, boolean verifyChecksums, BufferPool bufferPool) Creates a Snappy input stream to read data from the specified underlying channel.SnappyFramedInputStream(ReadableByteChannel in, BufferPool bufferPool) Creates a Snappy input stream to read data from the specified underlying channel. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidallocateBuffersBasedOnSize(int size) intvoidclose()private booleangetFrameData(ByteBuffer content) getFrameMetaData(ByteBuffer frameHeader) booleanisOpen()intread()intread(byte[] output, int offset, int length) intread(ByteBuffer dst) private booleanlongTransfers the entire content of thisInputStreamto os.longTransfers the entire content of thisReadableByteChannelto wbc.Methods inherited from class InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes
-
Field Details
-
crc32
-
rbc
-
frameHeader
-
verifyChecksums
private final boolean verifyChecksums -
bufferPool
-
input
A single frame read from the underlyingInputStream. -
uncompressedDirect
The decompressed data frominput. -
closed
private boolean closedIndicates if this instance has been closed. -
eof
private boolean eofIndicates if we have reached the EOF oninput. -
valid
private int validThe position ininputbuffer to read to. -
position
private int positionThe next position to read frombuffer. -
buffer
private byte[] bufferBuffer contains a copy of the uncompressed data for the block.
-
-
Constructor Details
-
SnappyFramedInputStream
Creates 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:
IOException
-
SnappyFramedInputStream
Creates 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:
IOException
-
SnappyFramedInputStream
Creates 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:
IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(InputStream in, boolean verifyChecksums, BufferPool bufferPool) throws IOException Creates 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:
IOException
-
SnappyFramedInputStream
Creates 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:
IOException
-
SnappyFramedInputStream
Creates 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:
IOException
-
SnappyFramedInputStream
Creates 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:
IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(ReadableByteChannel in, boolean verifyChecksums, BufferPool bufferPool) throws IOException Creates 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:
IOException
-
-
Method Details
-
allocateBuffersBasedOnSize
private void allocateBuffersBasedOnSize(int size) - Parameters:
size-
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
isOpen
-
read
- Specified by:
readin interfaceReadableByteChannel- Throws:
IOException
-
transferTo
Transfers 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 classInputStream- Parameters:
os- The destination to write decompressed content to.- Returns:
- The number of bytes transferred.
- Throws:
IOException- Since:
- 1.1.1
-
transferTo
Transfers 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:
IOException- Since:
- 1.1.1
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
ensureBuffer
- Throws:
IOException
-
readBlockHeader
- Throws:
IOException
-
getFrameMetaData
private SnappyFramedInputStream.FrameMetaData getFrameMetaData(ByteBuffer frameHeader) throws IOException - Parameters:
frameHeader-- Returns:
- Throws:
IOException
-
getFrameData
- Parameters:
content-- Returns:
- Throws:
IOException
-