@Signature public void __construct(Environment env, OutputStream outputStream, boolean framed) throws IOException { this.outputStream = framed ? new FramedLZ4CompressorOutputStream(outputStream) : new BlockLZ4CompressorOutputStream(outputStream); } }
private void clearUnusedBlocksAndPairs() { clearUnusedBlocks(); clearUnusedPairs(); }
private void addBackReference(LZ77Compressor.BackReference block) throws IOException { Pair last = writeBlocksAndReturnUnfinishedPair(block.getLength()); last.setBackReference(block); recordBackReference(block); clearUnusedBlocksAndPairs(); }
private void addLiteralBlock(LZ77Compressor.LiteralBlock block) throws IOException { Pair last = writeBlocksAndReturnUnfinishedPair(block.getLength()); recordLiteral(last.addLiteral(block)); clearUnusedBlocksAndPairs(); }
private void flushBlock() throws IOException { final boolean withBlockDependency = params.withBlockDependency; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (BlockLZ4CompressorOutputStream o = new BlockLZ4CompressorOutputStream(baos, params.lz77params)) { if (withBlockDependency) { o.prefill(blockDependencyBuffer, blockDependencyBuffer.length - collectedBlockDependencyBytes, collectedBlockDependencyBytes); o.write(blockData, 0, currentIndex);
/** * Creates a new LZ4 output stream. * * @param os * An OutputStream to read compressed data from * * @throws IOException if reading fails */ public BlockLZ4CompressorOutputStream(final OutputStream os) throws IOException { this(os, createParameterBuilder().build()); }
private void recordBackReference(LZ77Compressor.BackReference block) { expandedBlocks.addFirst(expand(block.getOffset(), block.getLength())); }
@Override public void close() throws IOException { try { finish(); } finally { os.close(); } }
private byte[] expand(final int offset, final int length) { byte[] expanded = new byte[length]; if (offset == 1) { // surprisingly common special case byte[] block = expandedBlocks.peekFirst(); byte b = block[block.length - 1]; if (b != 0) { // the fresh array contains 0s anyway Arrays.fill(expanded, b); } } else { expandFromList(expanded, offset, length); } return expanded; }
private void flushBlock() throws IOException { final boolean withBlockDependency = params.withBlockDependency; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (BlockLZ4CompressorOutputStream o = new BlockLZ4CompressorOutputStream(baos, params.lz77params)) { if (withBlockDependency) { o.prefill(blockDependencyBuffer, blockDependencyBuffer.length - collectedBlockDependencyBytes, collectedBlockDependencyBytes); o.write(blockData, 0, currentIndex);
private void addLiteralBlock(LZ77Compressor.LiteralBlock block) throws IOException { Pair last = writeBlocksAndReturnUnfinishedPair(block.getLength()); recordLiteral(last.addLiteral(block)); clearUnusedBlocksAndPairs(); }
/** * Sets up custom parameters for the LZ4 stream. * @param blockSize the size of a single block. * @param withContentChecksum whether to write a content checksum * @param withBlockChecksum whether to write a block checksum. * Note that block checksums are not supported by the lz4 * command line utility * @param withBlockDependency 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. */ public Parameters(BlockSize blockSize, boolean withContentChecksum, boolean withBlockChecksum, boolean withBlockDependency) { this(blockSize, withContentChecksum, withBlockChecksum, withBlockDependency, BlockLZ4CompressorOutputStream.createParameterBuilder().build()); }
replacement.prependLiteral(expand(toExpand, toExpand)); int brLen = splitCandidate.hasBackReference() ? splitCandidate.backReferenceLength() : 0; if (splitCandidate.hasBackReference() && brLen >= MIN_BACK_REFERENCE_LENGTH + stillNeeded) { replacement.prependLiteral(expand(toExpand + stillNeeded, stillNeeded)); pairs.add(splitCandidate.splitWithNewBackReferenceLengthOf(brLen - stillNeeded)); } else { if (splitCandidate.hasBackReference()) { replacement.prependLiteral(expand(toExpand + brLen, brLen));
@Override public void close() throws IOException { finish(); os.close(); }
private byte[] expand(final int offset, final int length) { byte[] expanded = new byte[length]; if (offset == 1) { // surprisingly common special case byte[] block = expandedBlocks.peekFirst(); byte b = block[block.length - 1]; if (b != 0) { // the fresh array contains 0s anyway Arrays.fill(expanded, b); } } else { expandFromList(expanded, offset, length); } return expanded; }
private void addBackReference(LZ77Compressor.BackReference block) throws IOException { Pair last = writeBlocksAndReturnUnfinishedPair(block.getLength()); last.setBackReference(block); recordBackReference(block); clearUnusedBlocksAndPairs(); }
private void clearUnusedBlocksAndPairs() { clearUnusedBlocks(); clearUnusedPairs(); }
/** * Creates a new LZ4 output stream. * * @param os * An OutputStream to read compressed data from * * @throws IOException if reading fails */ public BlockLZ4CompressorOutputStream(final OutputStream os) throws IOException { this(os, createParameterBuilder().build()); }
private void recordBackReference(LZ77Compressor.BackReference block) { expandedBlocks.addFirst(expand(block.getOffset(), block.getLength())); }