Package org.iq80.snappy
Class AbstractSnappyInputStream
java.lang.Object
java.io.InputStream
org.iq80.snappy.AbstractSnappyInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
SnappyFramedInputStream,SnappyInputStream
A common base class for frame based snappy input streams.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enumstatic final classstatic final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]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 booleanIndicates if this instance has been closed.private booleanIndicates if we have reached the EOF onin.private final byte[]private final InputStreamprivate byte[]A single frame read from the underlyingInputStream.private intThe next position to read frombuffer.private final BufferRecyclerprivate byte[]The decompressed data frominput.private intThe position ininputto read to.private final boolean -
Constructor Summary
ConstructorsConstructorDescriptionAbstractSnappyInputStream(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
Modifier and TypeMethodDescriptionprivate voidallocateBuffersBasedOnSize(int size) intvoidclose()private booleanprotected abstract AbstractSnappyInputStream.FrameDatagetFrameData(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.FrameMetaDatagetFrameMetaData(byte[] frameHeader) Use the content of the frameHeader to describe what type of frame we have and the action to take.intread()intread(byte[] output, int offset, int length) private booleanMethods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Field Details
-
in
-
frameHeader
private final byte[] frameHeader -
verifyChecksums
private final boolean verifyChecksums -
recycler
-
input
private byte[] inputA single frame read from the underlyingInputStream. -
uncompressed
private byte[] uncompressedThe decompressed data frominput. -
closed
private boolean closedIndicates if this instance has been closed. -
eof
private boolean eofIndicates if we have reached the EOF onin. -
valid
private int validThe position ininputto read to. -
position
private int positionThe next position to read frombuffer. -
buffer
private byte[] bufferBuffer 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 Details
-
AbstractSnappyInputStream
public AbstractSnappyInputStream(InputStream in, int maxBlockSize, int frameHeaderSize, boolean verifyChecksums, byte[] expectedHeader) throws 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:
IOException
-
-
Method Details
-
allocateBuffersBasedOnSize
private void allocateBuffersBasedOnSize(int size) -
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
ensureBuffer
- Throws:
IOException
-
getFrameMetaData
protected abstract AbstractSnappyInputStream.FrameMetaData getFrameMetaData(byte[] frameHeader) throws IOException Use the content of the frameHeader to describe what type of frame we have and the action to take.- Throws:
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
- Throws:
IOException
-