public final class SnappyFramedInputStream
extends java.io.InputStream
implements java.nio.channels.ReadableByteChannel
Modifier and Type | Class and Description |
---|---|
(package private) static class |
SnappyFramedInputStream.FrameAction |
static class |
SnappyFramedInputStream.FrameData |
static class |
SnappyFramedInputStream.FrameMetaData |
Modifier and Type | Field and Description |
---|---|
private byte[] |
buffer
Buffer contains a copy of the uncompressed data for the block.
|
private boolean |
closed
Indicates if this instance has been closed.
|
private boolean |
eof
Indicates if we have reached the EOF on
input . |
private java.nio.ByteBuffer |
frameHeader |
private java.nio.ByteBuffer |
input
A single frame read from the underlying
InputStream . |
private int |
position
The next position to read from
buffer . |
private java.nio.channels.ReadableByteChannel |
rbc |
private java.nio.ByteBuffer |
uncompressedDirect
The decompressed data from
input . |
private int |
valid
The position in
input buffer to read to. |
private boolean |
verifyChecksums |
Constructor and 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.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.
|
Modifier and Type | Method and Description |
---|---|
private void |
allocateBuffersBasedOnSize(int size) |
int |
available() |
void |
close() |
private boolean |
ensureBuffer() |
private int |
getCrc32c(java.nio.ByteBuffer content) |
private SnappyFramedInputStream.FrameData |
getFrameData(java.nio.ByteBuffer content) |
private SnappyFramedInputStream.FrameMetaData |
getFrameMetaData(java.nio.ByteBuffer frameHeader) |
boolean |
isOpen() |
int |
read() |
int |
read(byte[] output,
int offset,
int length) |
int |
read(java.nio.ByteBuffer dst) |
private boolean |
readBlockHeader() |
long |
transferTo(java.io.OutputStream os)
Transfers the entire content of this
InputStream to os. |
long |
transferTo(java.nio.channels.WritableByteChannel wbc)
Transfers the entire content of this
ReadableByteChannel to
wbc. |
private final java.nio.channels.ReadableByteChannel rbc
private final java.nio.ByteBuffer frameHeader
private final boolean verifyChecksums
private java.nio.ByteBuffer input
InputStream
.private java.nio.ByteBuffer uncompressedDirect
input
.private boolean closed
private boolean eof
input
.private int valid
input
buffer to read to.private int position
buffer
.private byte[] buffer
public SnappyFramedInputStream(java.io.InputStream in) throws java.io.IOException
in
- the underlying input stream. Must not be null
.java.io.IOException
public SnappyFramedInputStream(java.io.InputStream in, boolean verifyChecksums) throws java.io.IOException
in
- the underlying input stream. Must not be null
.verifyChecksums
- if true, checksums in input stream will be verifiedjava.io.IOException
public SnappyFramedInputStream(java.nio.channels.ReadableByteChannel in) throws java.io.IOException
in
- the underlying readable channel. Must not be null
.java.io.IOException
public SnappyFramedInputStream(java.nio.channels.ReadableByteChannel in, boolean verifyChecksums) throws java.io.IOException
in
- the underlying readable channel. Must not be null
.verifyChecksums
- if true, checksums in input stream will be verifiedjava.io.IOException
private void allocateBuffersBasedOnSize(int size)
size
- public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] output, int offset, int length) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
public boolean isOpen()
isOpen
in interface java.nio.channels.Channel
public int read(java.nio.ByteBuffer dst) throws java.io.IOException
read
in interface java.nio.channels.ReadableByteChannel
java.io.IOException
public long transferTo(java.io.OutputStream os) throws java.io.IOException
InputStream
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 of 0
.
os
- The destination to write decompressed content to.java.io.IOException
public long transferTo(java.nio.channels.WritableByteChannel wbc) throws java.io.IOException
ReadableByteChannel
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
of 0
.
wbc
- The destination to write decompressed content to.java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface java.nio.channels.Channel
close
in class java.io.InputStream
java.io.IOException
private boolean ensureBuffer() throws java.io.IOException
java.io.IOException
private boolean readBlockHeader() throws java.io.IOException
java.io.IOException
private SnappyFramedInputStream.FrameMetaData getFrameMetaData(java.nio.ByteBuffer frameHeader) throws java.io.IOException
frameHeader
- java.io.IOException
private SnappyFramedInputStream.FrameData getFrameData(java.nio.ByteBuffer content) throws java.io.IOException
content
- java.io.IOException
private int getCrc32c(java.nio.ByteBuffer content)