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

public Class BlockLZ4CompressorOutputStream

extends CompressorOutputStream
Class Inheritance
Imports
java.io.IOException, .OutputStream, java.util.Arrays, .Deque, .Iterator, .LinkedList, org.apache.commons.compress.compressors.CompressorOutputStream, org.apache.commons.compress.compressors.lz77support.LZ77Compressor, .Parameters, org.apache.commons.compress.utils.ByteUtils

CompressorOutputStream for the LZ4 block format.
Since
1.14
See Also
LZ4 Block Format Description

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private final LZ77Compressor
private final Deque<byte[]>
private boolean
private static final int
private static final int
private final byte[]
private final OutputStream
private final Deque<BlockLZ4CompressorOutputStream.Pair>

Constructor Summary

AccessConstructor and Description
public
BlockLZ4CompressorOutputStream(final OutputStream
An OutputStream to read compressed data from
os
)

Creates a new LZ4 output stream.

public
BlockLZ4CompressorOutputStream(final OutputStream
An OutputStream to read compressed data from
os
,
final Parameters
The parameters to use for LZ77 compression.
params
)

Creates a new LZ4 output stream.

Method Summary

Modifier and TypeMethod and Description
private void
private void
private void
private void
private void
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 static Parameters.Builder

Returns:

a builder correctly configured for the LZ4 algorithm
createParameterBuilder
()

Returns a builder correctly configured for the LZ4 algorithm.

private byte[]
expand(final int offset, final int length)

private void
expandFromList(final byte[] expanded, final int offset, final int length)

public void
finish()

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

public void
prefill(final byte[]
the data to fill the window with.
data
,
final int
offset of real data into the array
off
,
final int
amount of data
len
)

Adds some initial data to fill the window with.

private void
private void
recordLiteral(final byte[] b)

private void
public void
write(final byte[]
the data.
data
,
final int
the start offset in the data.
off
,
final 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 BlockLZ4CompressorOutputStream.Pair
private void
private void
writeWritablePairs(final int lengthOfBlocksAfterLastPair)

Field Detail

compressorback to summary
private final LZ77Compressor compressor
expandedBlocksback to summary
private final Deque<byte[]> expandedBlocks
finishedback to summary
private boolean finished
MIN_BACK_REFERENCE_LENGTHback to summary
private static final int MIN_BACK_REFERENCE_LENGTH
MIN_OFFSET_OF_LAST_BACK_REFERENCEback to summary
private static final int MIN_OFFSET_OF_LAST_BACK_REFERENCE
oneByteback to summary
private final byte[] oneByte
osback to summary
private final OutputStream os
pairsback to summary
private final Deque<BlockLZ4CompressorOutputStream.Pair> pairs

Constructor Detail

BlockLZ4CompressorOutputStreamback to summary
public BlockLZ4CompressorOutputStream(final OutputStream os)

Creates a new LZ4 output stream.

Parameters
os:OutputStream

An OutputStream to read compressed data from

BlockLZ4CompressorOutputStreamback to summary
public BlockLZ4CompressorOutputStream(final OutputStream os, final Parameters params)

Creates a new LZ4 output stream.

Parameters
os:OutputStream

An OutputStream to read compressed data from

params:Parameters

The parameters to use for LZ77 compression.

Method Detail

addBackReferenceback to summary
private void addBackReference(final LZ77Compressor.BackReference block) throws IOException
addLiteralBlockback to summary
private void addLiteralBlock(final LZ77Compressor.LiteralBlock block) throws IOException
clearUnusedBlocksback to summary
private void clearUnusedBlocks()
clearUnusedBlocksAndPairsback to summary
private void clearUnusedBlocksAndPairs()
clearUnusedPairsback to summary
private void clearUnusedPairs()
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.
createParameterBuilderback to summary
public static Parameters.Builder createParameterBuilder()

Returns a builder correctly configured for the LZ4 algorithm.

Returns:Parameters.Builder

a builder correctly configured for the LZ4 algorithm

expandback to summary
private byte[] expand(final int offset, final int length)
expandFromListback to summary
private void expandFromList(final byte[] expanded, final int offset, final int length)
finishback to summary
public void finish() throws IOException

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

Exceptions
IOException:
if an error occurs
prefillback to summary
public void prefill(final byte[] data, final int off, final int len)

Adds some initial data to fill the window with.

Parameters
data:byte[]

the data to fill the window with.

off:int

offset of real data into the array

len:int

amount of data

Exceptions
IllegalStateException:
if the stream has already started to write data
See Also
LZ77Compressor#prefill
recordBackReferenceback to summary
private void recordBackReference(final LZ77Compressor.BackReference block)
recordLiteralback to summary
private void recordLiteral(final byte[] b)
rewriteLastPairsback to summary
private void rewriteLastPairs()
writeback to summary
public void write(final byte[] data, final int off, final 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.
writeBlocksAndReturnUnfinishedPairback to summary
private BlockLZ4CompressorOutputStream.Pair writeBlocksAndReturnUnfinishedPair(final int length) throws IOException
writeFinalLiteralBlockback to summary
private void writeFinalLiteralBlock() throws IOException
writeWritablePairsback to summary
private void writeWritablePairs(final int lengthOfBlocksAfterLastPair) throws IOException
org.apache.commons.compress.compressors.lz4 back to summary

pack-priv final Class BlockLZ4CompressorOutputStream.Pair

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.compress.compressors.lz4.BlockLZ4CompressorOutputStream.Pair

Field Summary

Modifier and TypeField and Description
private int
private int
private int
private final Deque<byte[]>
private boolean

Constructor Summary

AccessConstructor and Description
pack-priv
Pair()

Method Summary

Modifier and TypeMethod and Description
pack-priv byte[]
private int
pack-priv boolean
canBeWritten(final int lengthOfBlocksAfterThisPair)

pack-priv boolean
private boolean
pack-priv int
private static int
lengths(final int litLength, final int brLength)

private int
private void
prependLiteral(final byte[] data)

private void
pack-priv void
private BlockLZ4CompressorOutputStream.Pair
splitWithNewBackReferenceLengthOf(final int newBackReferenceLength)

private static void
writeLength(int length, final OutputStream out)

pack-priv void
writeTo(final OutputStream out)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

brLengthback to summary
private int brLength
brOffsetback to summary
private int brOffset
literalLengthback to summary
private int literalLength
literalsback to summary
private final Deque<byte[]> literals
writtenback to summary
private boolean written

Constructor Detail

Pairback to summary
pack-priv Pair()

Method Detail

addLiteralback to summary
pack-priv byte[] addLiteral(final LZ77Compressor.LiteralBlock block)
backReferenceLengthback to summary
private int backReferenceLength()
canBeWrittenback to summary
pack-priv boolean canBeWritten(final int lengthOfBlocksAfterThisPair)
hasBackReferenceback to summary
pack-priv boolean hasBackReference()
hasBeenWrittenback to summary
private boolean hasBeenWritten()
lengthback to summary
pack-priv int length()
lengthsback to summary
private static int lengths(final int litLength, final int brLength)
literalLengthback to summary
private int literalLength()
prependLiteralback to summary
private void prependLiteral(final byte[] data)
prependToback to summary
private void prependTo(final BlockLZ4CompressorOutputStream.Pair other)
setBackReferenceback to summary
pack-priv void setBackReference(final LZ77Compressor.BackReference block)
splitWithNewBackReferenceLengthOfback to summary
private BlockLZ4CompressorOutputStream.Pair splitWithNewBackReferenceLengthOf(final int newBackReferenceLength)
writeLengthback to summary
private static void writeLength(int length, final OutputStream out) throws IOException
writeToback to summary
pack-priv void writeTo(final OutputStream out) throws IOException