Class BlockLZ4CompressorOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.commons.compress.compressors.CompressorOutputStream
-
- org.apache.commons.compress.compressors.lz4.BlockLZ4CompressorOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class BlockLZ4CompressorOutputStream extends CompressorOutputStream
CompressorOutputStream for the LZ4 block format.- Since:
- 1.14
- See Also:
- LZ4 Block Format Description
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
BlockLZ4CompressorOutputStream.Pair
-
Field Summary
Fields Modifier and Type Field Description private LZ77Compressor
compressor
private java.util.Deque<byte[]>
expandedBlocks
private boolean
finished
private static int
MIN_BACK_REFERENCE_LENGTH
private static int
MIN_OFFSET_OF_LAST_BACK_REFERENCE
private byte[]
oneByte
private java.io.OutputStream
os
private java.util.Deque<BlockLZ4CompressorOutputStream.Pair>
pairs
-
Constructor Summary
Constructors Constructor Description BlockLZ4CompressorOutputStream(java.io.OutputStream os)
Creates a new LZ4 output stream.BlockLZ4CompressorOutputStream(java.io.OutputStream os, Parameters params)
Creates a new LZ4 output stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addBackReference(LZ77Compressor.BackReference block)
private void
addLiteralBlock(LZ77Compressor.LiteralBlock block)
private void
clearUnusedBlocks()
private void
clearUnusedBlocksAndPairs()
private void
clearUnusedPairs()
void
close()
static Parameters.Builder
createParameterBuilder()
Returns a builder correctly configured for the LZ4 algorithm.private byte[]
expand(int offset, int length)
private void
expandFromList(byte[] expanded, int offset, int length)
void
finish()
Compresses all remaining data and writes it to the stream, doesn't close the underlying stream.void
prefill(byte[] data, int off, int len)
Adds some initial data to fill the window with.private void
recordBackReference(LZ77Compressor.BackReference block)
private void
recordLiteral(byte[] b)
private void
rewriteLastPairs()
void
write(byte[] data, int off, int len)
void
write(int b)
private BlockLZ4CompressorOutputStream.Pair
writeBlocksAndReturnUnfinishedPair(int length)
private void
writeFinalLiteralBlock()
private void
writeWritablePairs(int lengthOfBlocksAfterLastPair)
-
-
-
Field Detail
-
MIN_BACK_REFERENCE_LENGTH
private static final int MIN_BACK_REFERENCE_LENGTH
- See Also:
- Constant Field Values
-
MIN_OFFSET_OF_LAST_BACK_REFERENCE
private static final int MIN_OFFSET_OF_LAST_BACK_REFERENCE
- See Also:
- Constant Field Values
-
compressor
private final LZ77Compressor compressor
-
os
private final java.io.OutputStream os
-
oneByte
private final byte[] oneByte
-
finished
private boolean finished
-
pairs
private final java.util.Deque<BlockLZ4CompressorOutputStream.Pair> pairs
-
expandedBlocks
private final java.util.Deque<byte[]> expandedBlocks
-
-
Constructor Detail
-
BlockLZ4CompressorOutputStream
public BlockLZ4CompressorOutputStream(java.io.OutputStream os)
Creates a new LZ4 output stream.- Parameters:
os
- An OutputStream to read compressed data from
-
BlockLZ4CompressorOutputStream
public BlockLZ4CompressorOutputStream(java.io.OutputStream os, Parameters params)
Creates a new LZ4 output stream.- Parameters:
os
- An OutputStream to read compressed data fromparams
- The parameters to use for LZ77 compression.
-
-
Method Detail
-
createParameterBuilder
public static Parameters.Builder createParameterBuilder()
Returns a builder correctly configured for the LZ4 algorithm.- Returns:
- a builder correctly configured for the LZ4 algorithm
-
addBackReference
private void addBackReference(LZ77Compressor.BackReference block) throws java.io.IOException
- Throws:
java.io.IOException
-
addLiteralBlock
private void addLiteralBlock(LZ77Compressor.LiteralBlock block) throws java.io.IOException
- Throws:
java.io.IOException
-
clearUnusedBlocks
private void clearUnusedBlocks()
-
clearUnusedBlocksAndPairs
private void clearUnusedBlocksAndPairs()
-
clearUnusedPairs
private void clearUnusedPairs()
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
expand
private byte[] expand(int offset, int length)
-
expandFromList
private void expandFromList(byte[] expanded, int offset, int length)
-
finish
public void finish() throws java.io.IOException
Compresses all remaining data and writes it to the stream, doesn't close the underlying stream.- Throws:
java.io.IOException
- if an error occurs
-
prefill
public void prefill(byte[] data, int off, int len)
Adds some initial data to fill the window with.- Parameters:
data
- the data to fill the window with.off
- offset of real data into the arraylen
- amount of data- Throws:
java.lang.IllegalStateException
- if the stream has already started to write data- See Also:
LZ77Compressor.prefill(byte[])
-
recordBackReference
private void recordBackReference(LZ77Compressor.BackReference block)
-
recordLiteral
private void recordLiteral(byte[] b)
-
rewriteLastPairs
private void rewriteLastPairs()
-
write
public void write(byte[] data, int off, int len) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
writeBlocksAndReturnUnfinishedPair
private BlockLZ4CompressorOutputStream.Pair writeBlocksAndReturnUnfinishedPair(int length) throws java.io.IOException
- Throws:
java.io.IOException
-
writeFinalLiteralBlock
private void writeFinalLiteralBlock() throws java.io.IOException
- Throws:
java.io.IOException
-
writeWritablePairs
private void writeWritablePairs(int lengthOfBlocksAfterLastPair) throws java.io.IOException
- Throws:
java.io.IOException
-
-