Package org.iq80.snappy
Class AbstractSnappyInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.iq80.snappy.AbstractSnappyInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
SnappyFramedInputStream
,SnappyInputStream
abstract class AbstractSnappyInputStream extends java.io.InputStream
A common base class for frame based snappy input streams.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
AbstractSnappyInputStream.FrameAction
static class
AbstractSnappyInputStream.FrameData
static class
AbstractSnappyInputStream.FrameMetaData
-
Field Summary
Fields Modifier and Type Field Description private byte[]
buffer
Buffer is a reference to the real buffer of uncompressed data for the current block: uncompressed if the block is compressed, or input if it is not.private boolean
closed
Indicates if this instance has been closed.private boolean
eof
Indicates if we have reached the EOF onin
.private byte[]
frameHeader
private java.io.InputStream
in
private byte[]
input
A single frame read from the underlyingInputStream
.private int
position
The next position to read frombuffer
.private BufferRecycler
recycler
private byte[]
uncompressed
The decompressed data frominput
.private int
valid
The position ininput
to read to.private boolean
verifyChecksums
-
Constructor Summary
Constructors Constructor Description AbstractSnappyInputStream(java.io.InputStream in, int maxBlockSize, int frameHeaderSize, boolean verifyChecksums, byte[] expectedHeader)
Creates a Snappy input stream to read data from the specified underlying input stream.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private void
allocateBuffersBasedOnSize(int size)
int
available()
void
close()
private boolean
ensureBuffer()
protected abstract AbstractSnappyInputStream.FrameData
getFrameData(byte[] frameHeader, byte[] content, int length)
Take the frame header and the content of the frame to describe metadata about the content.protected abstract AbstractSnappyInputStream.FrameMetaData
getFrameMetaData(byte[] frameHeader)
Use the content of the frameHeader to describe what type of frame we have and the action to take.int
read()
int
read(byte[] output, int offset, int length)
private boolean
readBlockHeader()
-
-
-
Field Detail
-
in
private final java.io.InputStream in
-
frameHeader
private final byte[] frameHeader
-
verifyChecksums
private final boolean verifyChecksums
-
recycler
private final BufferRecycler recycler
-
input
private byte[] input
A single frame read from the underlyingInputStream
.
-
uncompressed
private byte[] uncompressed
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 onin
.
-
valid
private int valid
The position ininput
to read to.
-
position
private int position
The next position to read frombuffer
.
-
buffer
private byte[] buffer
Buffer is a reference to the real buffer of uncompressed data for the current block: uncompressed if the block is compressed, or input if it is not.
-
-
Constructor Detail
-
AbstractSnappyInputStream
public AbstractSnappyInputStream(java.io.InputStream in, int maxBlockSize, int frameHeaderSize, boolean verifyChecksums, byte[] expectedHeader) throws java.io.IOException
Creates a Snappy input stream to read data from the specified underlying input stream.- Parameters:
in
- the underlying input streamverifyChecksums
- if true, checksums in input stream will be verifiedexpectedHeader
- the expected stream header- Throws:
java.io.IOException
-
-
Method Detail
-
allocateBuffersBasedOnSize
private void allocateBuffersBasedOnSize(int 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
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- 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
-
getFrameMetaData
protected abstract AbstractSnappyInputStream.FrameMetaData getFrameMetaData(byte[] frameHeader) throws java.io.IOException
Use the content of the frameHeader to describe what type of frame we have and the action to take.- Throws:
java.io.IOException
-
getFrameData
protected abstract AbstractSnappyInputStream.FrameData getFrameData(byte[] frameHeader, byte[] content, int length)
Take the frame header and the content of the frame to describe metadata about the content.- Parameters:
frameHeader
- The frame header.content
- The content of the of the frame. Content begins at index0
.length
- The length of the content.- Returns:
- Metadata about the content of the frame.
-
readBlockHeader
private boolean readBlockHeader() throws java.io.IOException
- Throws:
java.io.IOException
-
-