public class FramedLZ4CompressorInputStream extends CompressorInputStream implements InputStreamStatistics
Based on the "spec" in the version "1.5.1 (31/03/2015)"
Modifier and Type | Field and Description |
---|---|
(package private) static int |
BLOCK_CHECKSUM_MASK |
(package private) static int |
BLOCK_INDEPENDENCE_MASK |
(package private) static int |
BLOCK_MAX_SIZE_MASK |
private byte[] |
blockDependencyBuffer |
private XXHash32 |
blockHash |
(package private) static int |
CONTENT_CHECKSUM_MASK |
(package private) static int |
CONTENT_SIZE_MASK |
private XXHash32 |
contentHash |
private java.io.InputStream |
currentBlock |
private boolean |
decompressConcatenated |
private boolean |
endReached |
private boolean |
expectBlockChecksum |
private boolean |
expectBlockDependency |
private boolean |
expectContentChecksum |
private boolean |
expectContentSize |
private CountingInputStream |
in |
private boolean |
inUncompressed |
(package private) static byte[] |
LZ4_SIGNATURE |
private byte[] |
oneByte |
private static byte |
SKIPPABLE_FRAME_PREFIX_BYTE_MASK |
private static byte[] |
SKIPPABLE_FRAME_TRAILER |
private ByteUtils.ByteSupplier |
supplier |
(package private) static int |
SUPPORTED_VERSION |
(package private) static int |
UNCOMPRESSED_FLAG_MASK |
(package private) static int |
VERSION_MASK |
Constructor and Description |
---|
FramedLZ4CompressorInputStream(java.io.InputStream in)
Creates a new input stream that decompresses streams compressed
using the LZ4 frame format and stops after decompressing the
first frame.
|
FramedLZ4CompressorInputStream(java.io.InputStream in,
boolean decompressConcatenated)
Creates a new input stream that decompresses streams compressed
using the LZ4 frame format.
|
Modifier and Type | Method and Description |
---|---|
private void |
appendToBlockDependencyBuffer(byte[] b,
int off,
int len) |
void |
close() |
long |
getCompressedCount() |
private void |
init(boolean firstFrame) |
private static boolean |
isSkippableFrameSignature(byte[] b) |
static boolean |
matches(byte[] signature,
int length)
Checks if the signature matches what is expected for a .lz4 file.
|
private void |
maybeFinishCurrentBlock() |
private void |
nextBlock() |
int |
read() |
int |
read(byte[] b,
int off,
int len) |
private void |
readFrameDescriptor() |
private int |
readOnce(byte[] b,
int off,
int len) |
private int |
readOneByte() |
private boolean |
readSignature(boolean firstFrame) |
private int |
skipSkippableFrame(byte[] b)
Skips over the contents of a skippable frame as well as
skippable frames following it.
|
private void |
verifyChecksum(XXHash32 hash,
java.lang.String kind) |
private void |
verifyContentChecksum() |
count, count, getBytesRead, getCount, getUncompressedCount, pushedBackBytes
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getUncompressedCount
static final byte[] LZ4_SIGNATURE
private static final byte[] SKIPPABLE_FRAME_TRAILER
private static final byte SKIPPABLE_FRAME_PREFIX_BYTE_MASK
static final int VERSION_MASK
static final int SUPPORTED_VERSION
static final int BLOCK_INDEPENDENCE_MASK
static final int BLOCK_CHECKSUM_MASK
static final int CONTENT_SIZE_MASK
static final int CONTENT_CHECKSUM_MASK
static final int BLOCK_MAX_SIZE_MASK
static final int UNCOMPRESSED_FLAG_MASK
private final byte[] oneByte
private final ByteUtils.ByteSupplier supplier
private final CountingInputStream in
private final boolean decompressConcatenated
private boolean expectBlockChecksum
private boolean expectBlockDependency
private boolean expectContentSize
private boolean expectContentChecksum
private java.io.InputStream currentBlock
private boolean endReached
private boolean inUncompressed
private final XXHash32 contentHash
private final XXHash32 blockHash
private byte[] blockDependencyBuffer
public FramedLZ4CompressorInputStream(java.io.InputStream in) throws java.io.IOException
in
- the InputStream from which to read the compressed datajava.io.IOException
- if reading failspublic FramedLZ4CompressorInputStream(java.io.InputStream in, boolean decompressConcatenated) throws java.io.IOException
in
- the InputStream from which to read the compressed datadecompressConcatenated
- 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 streamjava.io.IOException
- if reading failspublic int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public long getCompressedCount()
getCompressedCount
in interface InputStreamStatistics
private void init(boolean firstFrame) throws java.io.IOException
java.io.IOException
private boolean readSignature(boolean firstFrame) throws java.io.IOException
java.io.IOException
private void readFrameDescriptor() throws java.io.IOException
java.io.IOException
private void nextBlock() throws java.io.IOException
java.io.IOException
private void maybeFinishCurrentBlock() throws java.io.IOException
java.io.IOException
private void verifyContentChecksum() throws java.io.IOException
java.io.IOException
private void verifyChecksum(XXHash32 hash, java.lang.String kind) throws java.io.IOException
java.io.IOException
private int readOneByte() throws java.io.IOException
java.io.IOException
private int readOnce(byte[] b, int off, int len) throws java.io.IOException
java.io.IOException
private static boolean isSkippableFrameSignature(byte[] b)
private int skipSkippableFrame(byte[] b) throws java.io.IOException
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.
java.io.IOException
private void appendToBlockDependencyBuffer(byte[] b, int off, int len)
public static boolean matches(byte[] signature, int length)
.lz4 files start with a four byte signature.
signature
- the bytes to checklength
- the number of bytes to check