Top Description Fields Constructors Methods
org.apache.commons.compress.compressors.lz4

public Class FramedLZ4CompressorInputStream

extends CompressorInputStream
implements InputStreamStatistics
Class Inheritance
All Implemented Interfaces
org.apache.commons.compress.utils.InputStreamStatistics
Imports
java.io.IOException, .InputStream, java.util.Arrays, java.util.zip.CheckedInputStream, org.apache.commons.compress.compressors.CompressorInputStream, org.apache.commons.compress.utils.BoundedInputStream, .ByteUtils, .IOUtils, .InputStreamStatistics, org.apache.commons.io.input.CountingInputStream

CompressorInputStream for the LZ4 frame format.

Based on the "spec" in the version "1.5.1 (31/03/2015)"

Since
1.14
See Also
LZ4 Frame Format Description

Field Summary

Modifier and TypeField and Description
pack-priv static final int
pack-priv static final int
pack-priv static final int
private byte[]
blockDependencyBuffer

Only created if the frame doesn't set the block independence flag.

private final XXHash32
blockHash

Used for block checksum, if present.

pack-priv static final int
pack-priv static final int
private final XXHash32
contentHash

Used for frame header checksum and content checksum, if present.

private InputStream
private final boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private final CountingInputStream
private boolean
pack-priv static final byte[]
LZ4_SIGNATURE

Used by FramedLZ4CompressorOutputStream as well.

private final byte[]
oneByte

Used in no-arg read method.

private static final byte
private static final byte[]
private final ByteUtils.ByteSupplier
pack-priv static final int
pack-priv static final int
pack-priv static final int

Constructor Summary

AccessConstructor and Description
public
FramedLZ4CompressorInputStream(final InputStream
the InputStream from which to read the compressed data
in
)

Creates a new input stream that decompresses streams compressed using the LZ4 frame format and stops after decompressing the first frame.

public
FramedLZ4CompressorInputStream(final InputStream
the InputStream from which to read the compressed data
in
,
final boolean
if true, decompress until the end of the input; if false, stop after the first LZ4 frame and leave the input position to point to the next byte after the frame stream
decompressConcatenated
)

Creates a new input stream that decompresses streams compressed using the LZ4 frame format.

Method Summary

Modifier and TypeMethod and Description
private void
appendToBlockDependencyBuffer(final byte[] b, final int off, int len)

public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.
public long
getCompressedCount()

Implements org.apache.commons.compress.utils.InputStreamStatistics.getCompressedCount.

Gets the amount of raw or compressed bytes read by the stream.
private void
init(final boolean firstFrame)

private static boolean
isSkippableFrameSignature(final byte[] b)

public static boolean

Returns:

true if this is a .sz stream, false otherwise
matches
(final byte[]
the bytes to check
signature
,
final int
the number of bytes to check
length
)

Checks if the signature matches what is expected for a .lz4 file.

private void
private void
public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.
public int
read(final byte[]
the buffer into which the data is read.
b
,
final int
the start offset in array b at which the data is written.
off
,
final int
the maximum number of bytes to read.
len
)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.
private void
private int
readOnce(final byte[] b, final int off, final int len)

private int
private boolean
readSignature(final boolean firstFrame)

private int
skipSkippableFrame(final byte[] b)

Skips over the contents of a skippable frame as well as skippable frames following it.

private void
verifyChecksum(final XXHash32 hash, final String kind)

private void
Inherited from org.apache.commons.compress.compressors.CompressorInputStream:
countcountgetBytesReadgetCountgetUncompressedCountpushedBackBytes

Field Detail

BLOCK_CHECKSUM_MASKback to summary
pack-priv static final int BLOCK_CHECKSUM_MASK
BLOCK_INDEPENDENCE_MASKback to summary
pack-priv static final int BLOCK_INDEPENDENCE_MASK
BLOCK_MAX_SIZE_MASKback to summary
pack-priv static final int BLOCK_MAX_SIZE_MASK
blockDependencyBufferback to summary
private byte[] blockDependencyBuffer

Only created if the frame doesn't set the block independence flag.

blockHashback to summary
private final XXHash32 blockHash

Used for block checksum, if present.

CONTENT_CHECKSUM_MASKback to summary
pack-priv static final int CONTENT_CHECKSUM_MASK
CONTENT_SIZE_MASKback to summary
pack-priv static final int CONTENT_SIZE_MASK
contentHashback to summary
private final XXHash32 contentHash

Used for frame header checksum and content checksum, if present.

currentBlockback to summary
private InputStream currentBlock
decompressConcatenatedback to summary
private final boolean decompressConcatenated
endReachedback to summary
private boolean endReached
expectBlockChecksumback to summary
private boolean expectBlockChecksum
expectBlockDependencyback to summary
private boolean expectBlockDependency
expectContentChecksumback to summary
private boolean expectContentChecksum
expectContentSizeback to summary
private boolean expectContentSize
inputStreamback to summary
private final CountingInputStream inputStream
inUncompressedback to summary
private boolean inUncompressed
LZ4_SIGNATUREback to summary
pack-priv static final byte[] LZ4_SIGNATURE

Used by FramedLZ4CompressorOutputStream as well.

oneByteback to summary
private final byte[] oneByte

Used in no-arg read method.

SKIPPABLE_FRAME_PREFIX_BYTE_MASKback to summary
private static final byte SKIPPABLE_FRAME_PREFIX_BYTE_MASK
SKIPPABLE_FRAME_TRAILERback to summary
private static final byte[] SKIPPABLE_FRAME_TRAILER
supplierback to summary
private final ByteUtils.ByteSupplier supplier
SUPPORTED_VERSIONback to summary
pack-priv static final int SUPPORTED_VERSION
UNCOMPRESSED_FLAG_MASKback to summary
pack-priv static final int UNCOMPRESSED_FLAG_MASK
VERSION_MASKback to summary
pack-priv static final int VERSION_MASK

Constructor Detail

FramedLZ4CompressorInputStreamback to summary
public FramedLZ4CompressorInputStream(final InputStream in) throws IOException

Creates a new input stream that decompresses streams compressed using the LZ4 frame format and stops after decompressing the first frame.

Parameters
in:InputStream

the InputStream from which to read the compressed data

Exceptions
IOException:
if reading fails
FramedLZ4CompressorInputStreamback to summary
public FramedLZ4CompressorInputStream(final InputStream in, final boolean decompressConcatenated) throws IOException

Creates a new input stream that decompresses streams compressed using the LZ4 frame format.

Parameters
in:InputStream

the InputStream from which to read the compressed data

decompressConcatenated:boolean

if true, decompress until the end of the input; if false, stop after the first LZ4 frame and leave the input position to point to the next byte after the frame stream

Exceptions
IOException:
if reading fails

Method Detail

appendToBlockDependencyBufferback to summary
private void appendToBlockDependencyBuffer(final byte[] b, final int off, int len)
closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.InputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
getCompressedCountback to summary
public long getCompressedCount()

Implements org.apache.commons.compress.utils.InputStreamStatistics.getCompressedCount.

Doc from org.apache.commons.compress.utils.InputStreamStatistics.getCompressedCount.

Gets the amount of raw or compressed bytes read by the stream.

Returns:long

the amount of raw or compressed bytes read by the stream.

Annotations
@Override
Since
1.17
initback to summary
private void init(final boolean firstFrame) throws IOException
isSkippableFrameSignatureback to summary
private static boolean isSkippableFrameSignature(final byte[] b)
matchesback to summary
public static boolean matches(final byte[] signature, final int length)

Checks if the signature matches what is expected for a .lz4 file.

.lz4 files start with a four byte signature.

Parameters
signature:byte[]

the bytes to check

length:int

the number of bytes to check

Returns:boolean

true if this is a .sz stream, false otherwise

maybeFinishCurrentBlockback to summary
private void maybeFinishCurrentBlock() throws IOException
nextBlockback to summary
private void nextBlock() throws IOException
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(final byte[] b, final int off, final int len) 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
b:byte[]

the buffer into which the data is read.

off:int

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

len: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.
readFrameDescriptorback to summary
private void readFrameDescriptor() throws IOException
readOnceback to summary
private int readOnce(final byte[] b, final int off, final int len) throws IOException
readOneByteback to summary
private int readOneByte() throws IOException
readSignatureback to summary
private boolean readSignature(final boolean firstFrame) throws IOException
skipSkippableFrameback to summary
private int skipSkippableFrame(final byte[] b) throws IOException

Skips over the contents of a skippable frame as well as skippable frames following it.

It then tries to read four more bytes which are supposed to hold an LZ4 signature and returns the number of bytes read while storing the bytes in the given array.

verifyChecksumback to summary
private void verifyChecksum(final XXHash32 hash, final String kind) throws IOException
verifyContentChecksumback to summary
private void verifyContentChecksum() throws IOException