Top Description Inners Fields Constructors Methods
org.xerial.snappy

public final Class SnappyFramedInputStream

extends InputStream
implements ReadableByteChannel
Class Inheritance
All Implemented Interfaces
java.nio.channels.ReadableByteChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable
Static Imports
java.lang.Math.min, org.xerial.snappy.SnappyFramed.COMPRESSED_DATA_FLAG, .SnappyFramed.HEADER_BYTES, .SnappyFramed.STREAM_IDENTIFIER_FLAG, .SnappyFramed.UNCOMPRESSED_DATA_FLAG, .SnappyFramed.readBytes, .SnappyFramedOutputStream.MAX_BLOCK_SIZE

Implements the x-snappy-framed as an InputStream and ReadableByteChannel.
Author
Brett Okken
Since
1.1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum
public static class
public static class

Field Summary

Modifier and TypeField and Description
private byte[]
buffer

Buffer contains a copy of the uncompressed data for the block.

private final BufferPool
private boolean
closed

Indicates if this instance has been closed.

private final Checksum
private boolean
eof

Indicates if we have reached the EOF on input.

private final ByteBuffer
private ByteBuffer
input

A single frame read from the underlying InputStream.

private int
position

The next position to read from buffer.

private final ReadableByteChannel
private ByteBuffer
uncompressedDirect

The decompressed data from input.

private int
valid

The position in input buffer to read to.

private final boolean

Constructor Summary

AccessConstructor and Description
public
SnappyFramedInputStream(InputStream
the underlying input stream. Must not be null.
in
)

Creates a Snappy input stream to read data from the specified underlying input stream.

public
SnappyFramedInputStream(InputStream
the underlying input stream. Must not be null.
in
,
BufferPool
Used to obtain buffer instances. Must not be null.
bufferPool
)

Creates a Snappy input stream to read data from the specified underlying input stream.

public
SnappyFramedInputStream(InputStream
the underlying input stream. Must not be null.
in
,
boolean
if true, checksums in input stream will be verified
verifyChecksums
)

Creates a Snappy input stream to read data from the specified underlying input stream.

public
SnappyFramedInputStream(InputStream
the underlying input stream. Must not be null.
in
,
boolean
if true, checksums in input stream will be verified
verifyChecksums
,
BufferPool
Used to obtain buffer instances. Must not be null.
bufferPool
)

Creates a Snappy input stream to read data from the specified underlying input stream.

public
SnappyFramedInputStream(ReadableByteChannel
the underlying readable channel. Must not be null.
in
,
BufferPool
Used to obtain buffer instances. Must not be null.
bufferPool
)

Creates a Snappy input stream to read data from the specified underlying channel.

public
SnappyFramedInputStream(ReadableByteChannel
the underlying readable channel. Must not be null.
in
)

Creates a Snappy input stream to read data from the specified underlying channel.

public
SnappyFramedInputStream(ReadableByteChannel
the underlying readable channel. Must not be null.
in
,
boolean
if true, checksums in input stream will be verified
verifyChecksums
)

Creates a Snappy input stream to read data from the specified underlying channel.

public
SnappyFramedInputStream(ReadableByteChannel
the underlying readable channel. Must not be null.
in
,
boolean
if true, checksums in input stream will be verified
verifyChecksums
,
BufferPool
Used to obtain buffer instances. Must not be null.
bufferPool
)

Creates a Snappy input stream to read data from the specified underlying channel.

Method Summary

Modifier and TypeMethod and Description
private void
public int
available()

Overrides java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected.

public void
private boolean
private int
private SnappyFramedInputStream.FrameData
private SnappyFramedInputStream.FrameMetaData
public boolean
isOpen()

Implements java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.

public int
read(byte[]
the buffer into which the data is read.
output
,
int
the start offset in array b at which the data is written.
offset
,
int
the maximum number of bytes to read.
length
)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.

public int
read(ByteBuffer
The buffer into which bytes are to be transferred
dst
)

Implements java.nio.channels.ReadableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

private boolean
public long

Returns:

The number of bytes transferred.
transferTo
(OutputStream
The destination to write decompressed content to.
os
)

Overrides java.io.InputStream.transferTo.

Transfers the entire content of this InputStream to os.

public long

Returns:

The number of bytes transferred.
transferTo
(WritableByteChannel
The destination to write decompressed content to.
wbc
)

Transfers the entire content of this ReadableByteChannel to wbc.

Inherited from java.io.InputStream:
markmarkSupportednullInputStreamreadreadAllBytesreadNBytesreadNBytesresetskipskipNBytes

Field Detail

bufferback to summary
private byte[] buffer

Buffer contains a copy of the uncompressed data for the block.

bufferPoolback to summary
private final BufferPool bufferPool
closedback to summary
private boolean closed

Indicates if this instance has been closed.

crc32back to summary
private final Checksum crc32
eofback to summary
private boolean eof

Indicates if we have reached the EOF on input.

frameHeaderback to summary
private final ByteBuffer frameHeader
inputback to summary
private ByteBuffer input

A single frame read from the underlying InputStream.

positionback to summary
private int position

The next position to read from buffer.

rbcback to summary
private final ReadableByteChannel rbc
uncompressedDirectback to summary
private ByteBuffer uncompressedDirect

The decompressed data from input.

validback to summary
private int valid

The position in input buffer to read to.

verifyChecksumsback to summary
private final boolean verifyChecksums

Constructor Detail

SnappyFramedInputStreamback to summary
public SnappyFramedInputStream(InputStream in) throws IOException

Creates a Snappy input stream to read data from the specified underlying input stream.

Uses DefaultPoolFactory to obtain BufferPool for buffers.

Parameters
in:InputStream

the underlying input stream. Must not be null.

SnappyFramedInputStreamback to summary
public SnappyFramedInputStream(InputStream in, BufferPool bufferPool) throws IOException

Creates a Snappy input stream to read data from the specified underlying input stream.

Parameters
in:InputStream

the underlying input stream. Must not be null.

bufferPool:BufferPool

Used to obtain buffer instances. Must not be null.

SnappyFramedInputStreamback to summary
public SnappyFramedInputStream(InputStream in, boolean verifyChecksums) throws IOException

Creates a Snappy input stream to read data from the specified underlying input stream.

Uses DefaultPoolFactory to obtain BufferPool for buffers.

Parameters
in:InputStream

the underlying input stream. Must not be null.

verifyChecksums:boolean

if true, checksums in input stream will be verified

SnappyFramedInputStreamback to summary
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:InputStream

the underlying input stream. Must not be null.

verifyChecksums:boolean

if true, checksums in input stream will be verified

bufferPool:BufferPool

Used to obtain buffer instances. Must not be null.

SnappyFramedInputStreamback to summary
public SnappyFramedInputStream(ReadableByteChannel in, BufferPool bufferPool) throws IOException

Creates a Snappy input stream to read data from the specified underlying channel.

Parameters
in:ReadableByteChannel

the underlying readable channel. Must not be null.

bufferPool:BufferPool

Used to obtain buffer instances. Must not be null.

SnappyFramedInputStreamback to summary
public SnappyFramedInputStream(ReadableByteChannel in) throws IOException

Creates a Snappy input stream to read data from the specified underlying channel.

Uses DefaultPoolFactory to obtain BufferPool for buffers.

Parameters
in:ReadableByteChannel

the underlying readable channel. Must not be null.

SnappyFramedInputStreamback to summary
public SnappyFramedInputStream(ReadableByteChannel in, boolean verifyChecksums) throws IOException

Creates a Snappy input stream to read data from the specified underlying channel.

Uses DefaultPoolFactory to obtain BufferPool for buffers.

Parameters
in:ReadableByteChannel

the underlying readable channel. Must not be null.

verifyChecksums:boolean

if true, checksums in input stream will be verified

SnappyFramedInputStreamback to summary
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:ReadableByteChannel

the underlying readable channel. Must not be null.

verifyChecksums:boolean

if true, checksums in input stream will be verified

bufferPool:BufferPool

Used to obtain buffer instances. Must not be null.

Method Detail

allocateBuffersBasedOnSizeback to summary
private void allocateBuffersBasedOnSize(int size)
availableback to summary
public int available() throws IOException

Overrides java.io.InputStream.available.

Doc from java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.

A subclass's implementation of this method may choose to throw an IOException if this input stream has been closed by invoking the close() method.

Returns:int

an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking or 0 when it reaches the end of the input stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.nio.channels.Channel.close, java.io.Closeable.close.

Doc from java.nio.channels.Channel.close.

Closes this channel.

After a channel is closed, any further attempt to invoke I/O operations upon it will cause a ClosedChannelException to be thrown.

If this channel is already closed then invoking this method has no effect.

This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
ensureBufferback to summary
private boolean ensureBuffer() throws IOException
getCrc32cback to summary
private int getCrc32c(ByteBuffer content)
getFrameDataback to summary
private SnappyFramedInputStream.FrameData getFrameData(ByteBuffer content) throws IOException
getFrameMetaDataback to summary
private SnappyFramedInputStream.FrameMetaData getFrameMetaData(ByteBuffer frameHeader) throws IOException
isOpenback to summary
public boolean isOpen()

Implements java.nio.channels.Channel.isOpen.

Doc from java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

Returns:boolean

true if, and only if, this channel is open

Annotations
@Override
readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(byte[] output, int offset, int length) throws IOException

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off-1] and elements b[off+len] through b[b.length-1] are unaffected.

Parameters
output:byte[]

the buffer into which the data is read.

offset:int

the start offset in array b at which the data is written.

length:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.
readback to summary
public int read(ByteBuffer dst) throws IOException

Implements java.nio.channels.ReadableByteChannel.read.

Doc from java.nio.channels.ReadableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

An attempt is made to read up to r bytes from the channel, where r is the number of bytes remaining in the buffer, that is, dst.remaining(), at the moment this method is invoked.

Suppose that a byte sequence of length n is read, where 0 <= n <= r. This byte sequence will be transferred into the buffer so that the first byte in the sequence is at index p and the last byte is at index p + n - 1, where p is the buffer's position at the moment this method is invoked. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

A read operation might not fill the buffer, and in fact it might not read any bytes at all. Whether or not it does so depends upon the nature and state of the channel. A socket channel in non-blocking mode, for example, cannot read any more bytes than are immediately available from the socket's input buffer; similarly, a file channel cannot read any more bytes than remain in the file. It is guaranteed, however, that if a channel is in blocking mode and there is at least one byte remaining in the buffer then this method will block until at least one byte is read.

This method may be invoked at any time. If another thread has already initiated a read operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Parameters
dst:ByteBuffer

The buffer into which bytes are to be transferred

Returns:int

The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
readBlockHeaderback to summary
private boolean readBlockHeader() throws IOException
transferToback to summary
public long transferTo(OutputStream os) throws IOException

Overrides java.io.InputStream.transferTo.

Transfers the entire content of this 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.

Parameters
os:OutputStream

The destination to write decompressed content to.

Returns:long

The number of bytes transferred.

Exceptions
IOException:

Doc from java.io.InputStream.transferTo.

if an I/O error occurs when reading or writing

Since
1.1.1
transferToback to summary
public long transferTo(WritableByteChannel wbc) throws IOException

Transfers the entire content of this 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.

Parameters
wbc:WritableByteChannel

The destination to write decompressed content to.

Returns:long

The number of bytes transferred.

Since
1.1.1
org.xerial.snappy back to summary

pack-priv final Enum SnappyFramedInputStream.FrameAction

extends Enum<SnappyFramedInputStream.FrameAction>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final SnappyFramedInputStream.FrameAction
public static final SnappyFramedInputStream.FrameAction
public static final SnappyFramedInputStream.FrameAction

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static SnappyFramedInputStream.FrameAction
public static SnappyFramedInputStream.FrameAction[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

RAWback to summary
public static final SnappyFramedInputStream.FrameAction RAW
SKIPback to summary
public static final SnappyFramedInputStream.FrameAction SKIP
UNCOMPRESSback to summary
public static final SnappyFramedInputStream.FrameAction UNCOMPRESS

Constructor Detail

FrameActionback to summary
private FrameAction()

Method Detail

valueOfback to summary
public static SnappyFramedInputStream.FrameAction valueOf(String name)
valuesback to summary
public static SnappyFramedInputStream.FrameAction[] values()
org.xerial.snappy back to summary

public final Class SnappyFramedInputStream.FrameData

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final int
pack-priv final int

Constructor Summary

AccessConstructor and Description
public
FrameData(int checkSum, int offset)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

checkSumback to summary
pack-priv final int checkSum
offsetback to summary
pack-priv final int offset

Constructor Detail

FrameDataback to summary
public FrameData(int checkSum, int offset)
org.xerial.snappy back to summary

public final Class SnappyFramedInputStream.FrameMetaData

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final SnappyFramedInputStream.FrameAction
pack-priv final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

frameActionback to summary
pack-priv final SnappyFramedInputStream.FrameAction frameAction
lengthback to summary
pack-priv final int length

Constructor Detail

FrameMetaDataback to summary
public FrameMetaData(SnappyFramedInputStream.FrameAction frameAction, int length)