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

public Class FramedLZ4CompressorOutputStream

extends CompressorOutputStream
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .IOException, .OutputStream, org.apache.commons.compress.compressors.CompressorOutputStream, org.apache.commons.compress.utils.ByteUtils

CompressorOutputStream 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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
FramedLZ4CompressorOutputStream.BlockSize

The block sizes supported by the format.

public static class
FramedLZ4CompressorOutputStream.Parameters

Parameters of the LZ4 frame format.

Field Summary

Modifier and TypeField and Description
private final byte[]
private final byte[]
private final XXHash32
private int
private final XXHash32
private int
private static final byte[]
private boolean
private final byte[]
private final OutputStream
private final FramedLZ4CompressorOutputStream.Parameters

Constructor Summary

AccessConstructor and Description
public
FramedLZ4CompressorOutputStream(final OutputStream
the OutputStream to which to write the compressed data
out
)

Constructs a new output stream that compresses data using the LZ4 frame format using the default block size of 4MB.

public
FramedLZ4CompressorOutputStream(final OutputStream
the OutputStream to which to write the compressed data
out
,
final FramedLZ4CompressorOutputStream.Parameters
the parameters to use
params
)

Constructs a new output stream that compresses data using the LZ4 frame format using the given block size.

Method Summary

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

public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.
public void
finish()

Compresses all blockDataRemaining data and writes it to the stream, doesn't close the underlying stream.

private void
public void
write(final byte[]
the data.
data
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.
public void
write(final int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.
private void
private void

Field Detail

blockDataback to summary
private final byte[] blockData
blockDependencyBufferback to summary
private final byte[] blockDependencyBuffer
blockHashback to summary
private final XXHash32 blockHash
collectedBlockDependencyBytesback to summary
private int collectedBlockDependencyBytes
contentHashback to summary
private final XXHash32 contentHash
currentIndexback to summary
private int currentIndex
END_MARKback to summary
private static final byte[] END_MARK
finishedback to summary
private boolean finished
oneByteback to summary
private final byte[] oneByte
outback to summary
private final OutputStream out
paramsback to summary
private final FramedLZ4CompressorOutputStream.Parameters params

Constructor Detail

FramedLZ4CompressorOutputStreamback to summary
public FramedLZ4CompressorOutputStream(final OutputStream out) throws IOException

Constructs a new output stream that compresses data using the LZ4 frame format using the default block size of 4MB.

Parameters
out:OutputStream

the OutputStream to which to write the compressed data

Exceptions
IOException:
if writing the signature fails
FramedLZ4CompressorOutputStreamback to summary
public FramedLZ4CompressorOutputStream(final OutputStream out, final FramedLZ4CompressorOutputStream.Parameters params) throws IOException

Constructs a new output stream that compresses data using the LZ4 frame format using the given block size.

Parameters
out:OutputStream

the OutputStream to which to write the compressed data

params:FramedLZ4CompressorOutputStream.Parameters

the parameters to use

Exceptions
IOException:
if writing the signature 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.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

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

Compresses all blockDataRemaining data and writes it to the stream, doesn't close the underlying stream.

Exceptions
IOException:
if an error occurs
flushBlockback to summary
private void flushBlock() throws IOException
writeback to summary
public void write(final byte[] data, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
data:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
writeback to summary
public void write(final int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeFrameDescriptorback to summary
private void writeFrameDescriptor() throws IOException
writeTrailerback to summary
private void writeTrailer() throws IOException
org.apache.commons.compress.compressors.lz4 back to summary

public final Enum FramedLZ4CompressorOutputStream.BlockSize

extends Enum<FramedLZ4CompressorOutputStream.BlockSize>
Class Inheritance

The block sizes supported by the format.

Field Summary

Modifier and TypeField and Description
private final int
public static final FramedLZ4CompressorOutputStream.BlockSize
K256

Block size of 256K

public static final FramedLZ4CompressorOutputStream.BlockSize
K64

Block size of 64K

public static final FramedLZ4CompressorOutputStream.BlockSize
M1

Block size of 1M

public static final FramedLZ4CompressorOutputStream.BlockSize
M4

Block size of 4M

private final int

Constructor Summary

AccessConstructor and Description
private
BlockSize(final int size, final int index)

Method Summary

Modifier and TypeMethod and Description
pack-priv int
pack-priv int
public static FramedLZ4CompressorOutputStream.BlockSize
public static FramedLZ4CompressorOutputStream.BlockSize[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

indexback to summary
private final int index
K256back to summary
public static final FramedLZ4CompressorOutputStream.BlockSize K256

Block size of 256K

K64back to summary
public static final FramedLZ4CompressorOutputStream.BlockSize K64

Block size of 64K

M1back to summary
public static final FramedLZ4CompressorOutputStream.BlockSize M1

Block size of 1M

M4back to summary
public static final FramedLZ4CompressorOutputStream.BlockSize M4

Block size of 4M

sizeback to summary
private final int size

Constructor Detail

BlockSizeback to summary
private BlockSize(final int size, final int index)

Method Detail

getIndexback to summary
pack-priv int getIndex()
getSizeback to summary
pack-priv int getSize()
valueOfback to summary
public static FramedLZ4CompressorOutputStream.BlockSize valueOf(String name)
valuesback to summary
public static FramedLZ4CompressorOutputStream.BlockSize[] values()
org.apache.commons.compress.compressors.lz4 back to summary

public Class FramedLZ4CompressorOutputStream.Parameters

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.compress.compressors.lz4.FramedLZ4CompressorOutputStream.Parameters

Parameters of the LZ4 frame format.

Field Summary

Modifier and TypeField and Description
private final FramedLZ4CompressorOutputStream.BlockSize
public static final FramedLZ4CompressorOutputStream.Parameters
DEFAULT

The default parameters of 4M block size, enabled content checksum, disabled block checksums and independent blocks.

private final Parameters
private final boolean
private final boolean
private final boolean

Constructor Summary

AccessConstructor and Description
public
Parameters(final FramedLZ4CompressorOutputStream.BlockSize
the size of a single block.
blockSize
)

Sets up custom a custom block size for the LZ4 stream but otherwise uses the defaults of enabled content checksum, disabled block checksums and independent blocks.

public
Parameters(final FramedLZ4CompressorOutputStream.BlockSize
the size of a single block.
blockSize
,
final boolean
whether to write a content checksum
withContentChecksum
,
final boolean
whether to write a block checksum. Note that block checksums are not supported by the lz4 command line utility
withBlockChecksum
,
final boolean
whether a block may depend on the content of a previous block. Enabling this may improve compression ratio but makes it impossible to decompress the output in parallel.
withBlockDependency
)

Sets up custom parameters for the LZ4 stream.

public
Parameters(final FramedLZ4CompressorOutputStream.BlockSize
the size of a single block.
blockSize
,
final boolean
whether to write a content checksum
withContentChecksum
,
final boolean
whether to write a block checksum. Note that block checksums are not supported by the lz4 command line utility
withBlockChecksum
,
final boolean
whether a block may depend on the content of a previous block. Enabling this may improve compression ratio but makes it impossible to decompress the output in parallel.
withBlockDependency
,
final Parameters
parameters used to fine-tune compression, in particular to balance compression ratio vs compression speed.
lz77params
)

Sets up custom parameters for the LZ4 stream.

public
Parameters(final FramedLZ4CompressorOutputStream.BlockSize
the size of a single block.
blockSize
,
final Parameters
parameters used to fine-tune compression, in particular to balance compression ratio vs compression speed.
lz77params
)

Sets up custom a custom block size for the LZ4 stream but otherwise uses the defaults of enabled content checksum, disabled block checksums and independent blocks.

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

blockSizeback to summary
private final FramedLZ4CompressorOutputStream.BlockSize blockSize
DEFAULTback to summary
public static final FramedLZ4CompressorOutputStream.Parameters DEFAULT

The default parameters of 4M block size, enabled content checksum, disabled block checksums and independent blocks.

This matches the defaults of the lz4 command line utility.

lz77paramsback to summary
private final Parameters lz77params
withBlockChecksumback to summary
private final boolean withBlockChecksum
withBlockDependencyback to summary
private final boolean withBlockDependency
withContentChecksumback to summary
private final boolean withContentChecksum

Constructor Detail

Parametersback to summary
public Parameters(final FramedLZ4CompressorOutputStream.BlockSize blockSize)

Sets up custom a custom block size for the LZ4 stream but otherwise uses the defaults of enabled content checksum, disabled block checksums and independent blocks.

Parameters
blockSize:FramedLZ4CompressorOutputStream.BlockSize

the size of a single block.

Parametersback to summary
public Parameters(final FramedLZ4CompressorOutputStream.BlockSize blockSize, final boolean withContentChecksum, final boolean withBlockChecksum, final boolean withBlockDependency)

Sets up custom parameters for the LZ4 stream.

Parameters
blockSize:FramedLZ4CompressorOutputStream.BlockSize

the size of a single block.

withContentChecksum:boolean

whether to write a content checksum

withBlockChecksum:boolean

whether to write a block checksum. Note that block checksums are not supported by the lz4 command line utility

withBlockDependency:boolean

whether a block may depend on the content of a previous block. Enabling this may improve compression ratio but makes it impossible to decompress the output in parallel.

Parametersback to summary
public Parameters(final FramedLZ4CompressorOutputStream.BlockSize blockSize, final boolean withContentChecksum, final boolean withBlockChecksum, final boolean withBlockDependency, final Parameters lz77params)

Sets up custom parameters for the LZ4 stream.

Parameters
blockSize:FramedLZ4CompressorOutputStream.BlockSize

the size of a single block.

withContentChecksum:boolean

whether to write a content checksum

withBlockChecksum:boolean

whether to write a block checksum. Note that block checksums are not supported by the lz4 command line utility

withBlockDependency:boolean

whether a block may depend on the content of a previous block. Enabling this may improve compression ratio but makes it impossible to decompress the output in parallel.

lz77params:Parameters

parameters used to fine-tune compression, in particular to balance compression ratio vs compression speed.

Parametersback to summary
public Parameters(final FramedLZ4CompressorOutputStream.BlockSize blockSize, final Parameters lz77params)

Sets up custom a custom block size for the LZ4 stream but otherwise uses the defaults of enabled content checksum, disabled block checksums and independent blocks.

Parameters
blockSize:FramedLZ4CompressorOutputStream.BlockSize

the size of a single block.

lz77params:Parameters

parameters used to fine-tune compression, in particular to balance compression ratio vs compression speed.

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override