Package org.xerial.snappy
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 enum
static final class
static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]
Buffer contains a copy of the uncompressed data for the block.private final BufferPool
private boolean
Indicates if this instance has been closed.private final Checksum
private boolean
Indicates if we have reached the EOF oninput
.private final ByteBuffer
private ByteBuffer
A single frame read from the underlyingInputStream
.private int
The next position to read frombuffer
.private final ReadableByteChannel
private ByteBuffer
The decompressed data frominput
.private int
The position ininput
buffer 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 void
allocateBuffersBasedOnSize
(int size) int
void
close()
private boolean
getFrameData
(ByteBuffer content) getFrameMetaData
(ByteBuffer frameHeader) boolean
isOpen()
int
read()
int
read
(byte[] output, int offset, int length) int
read
(ByteBuffer dst) private boolean
long
Transfers the entire content of thisInputStream
to os.long
Transfers the entire content of thisReadableByteChannel
to wbc.Methods inherited from class java.io.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 ininput
buffer 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
DefaultPoolFactory
to obtainBufferPool
for 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
DefaultPoolFactory
to obtainBufferPool
for 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
DefaultPoolFactory
to obtainBufferPool
for 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
DefaultPoolFactory
to obtainBufferPool
for 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:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classInputStream
- Throws:
IOException
-
isOpen
public boolean isOpen() -
read
- Specified by:
read
in interfaceReadableByteChannel
- Throws:
IOException
-
transferTo
Transfers the entire content of thisInputStream
to 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:
transferTo
in 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 thisReadableByteChannel
to 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in 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
-