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 class
SnappyFramedInputStream.FrameAction
static class
SnappyFramedInputStream.FrameData
static class
SnappyFramedInputStream.FrameMetaData
-
Field Summary
Fields Modifier and Type Field Description private byte[]
buffer
Buffer contains a copy of the uncompressed data for the block.private BufferPool
bufferPool
private boolean
closed
Indicates if this instance has been closed.private java.util.zip.Checksum
crc32
private boolean
eof
Indicates if we have reached the EOF oninput
.private java.nio.ByteBuffer
frameHeader
private java.nio.ByteBuffer
input
A single frame read from the underlyingInputStream
.private int
position
The next position to read frombuffer
.private java.nio.channels.ReadableByteChannel
rbc
private java.nio.ByteBuffer
uncompressedDirect
The decompressed data frominput
.private int
valid
The position ininput
buffer to read to.private boolean
verifyChecksums
-
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 void
allocateBuffersBasedOnSize(int size)
int
available()
void
close()
private boolean
ensureBuffer()
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 thisInputStream
to os.long
transferTo(java.nio.channels.WritableByteChannel wbc)
Transfers the entire content of thisReadableByteChannel
to 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 ininput
buffer 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.IOException
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:
java.io.IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(java.io.InputStream in, BufferPool bufferPool) throws java.io.IOException
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:
java.io.IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(java.io.InputStream in, boolean verifyChecksums) throws java.io.IOException
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:
java.io.IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(java.io.InputStream in, boolean verifyChecksums, BufferPool bufferPool) throws java.io.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:
java.io.IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(java.nio.channels.ReadableByteChannel in, BufferPool bufferPool) throws java.io.IOException
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:
java.io.IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(java.nio.channels.ReadableByteChannel in) throws java.io.IOException
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:
java.io.IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(java.nio.channels.ReadableByteChannel in, boolean verifyChecksums) throws java.io.IOException
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:
java.io.IOException
-
SnappyFramedInputStream
public SnappyFramedInputStream(java.nio.channels.ReadableByteChannel in, boolean verifyChecksums, BufferPool bufferPool) throws java.io.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:
java.io.IOException
-
-
Method Detail
-
allocateBuffersBasedOnSize
private void allocateBuffersBasedOnSize(int size)
- Parameters:
size
-
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] output, int offset, int length) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException
- Overrides:
available
in classjava.io.InputStream
- Throws:
java.io.IOException
-
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interfacejava.nio.channels.Channel
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOException
- Specified by:
read
in interfacejava.nio.channels.ReadableByteChannel
- Throws:
java.io.IOException
-
transferTo
public long transferTo(java.io.OutputStream os) throws java.io.IOException
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 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.IOException
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:
java.io.IOException
- Since:
- 1.1.1
-
close
public 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.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
-
-