private void verifyContentChecksum() throws IOException { if (expectContentChecksum) { verifyChecksum(contentHash, "content"); } contentHash.reset(); }
@Override public void write(int b) throws IOException { oneByte[0] = (byte) (b & 0xff); write(oneByte); }
/** {@inheritDoc} */ @Override public int read() throws IOException { return read(oneByte, 0, 1) == -1 ? -1 : oneByte[0] & 0xFF; }
private void addLiteralBlock(LZ77Compressor.LiteralBlock block) throws IOException { Pair last = writeBlocksAndReturnUnfinishedPair(block.getLength()); recordLiteral(last.addLiteral(block)); clearUnusedBlocksAndPairs(); }
private void addBackReference(LZ77Compressor.BackReference block) throws IOException { Pair last = writeBlocksAndReturnUnfinishedPair(block.getLength()); last.setBackReference(block); recordBackReference(block); clearUnusedBlocksAndPairs(); }
@Signature public void __construct(Environment env, OutputStream outputStream, boolean framed) throws IOException { this.outputStream = framed ? new FramedLZ4CompressorOutputStream(outputStream) : new BlockLZ4CompressorOutputStream(outputStream); } }
@Signature public void __construct(Environment env, InputStream inputStream, boolean framed) throws IOException { this.inputStream = framed ? new FramedLZ4CompressorInputStream(inputStream) : new BlockLZ4CompressorInputStream(inputStream); } }
private void init(boolean firstFrame) throws IOException { if (readSignature(firstFrame)) { readFrameDescriptor(); nextBlock(); } }
private Pair writeBlocksAndReturnUnfinishedPair(int length) throws IOException { writeWritablePairs(length); Pair last = pairs.peekLast(); if (last == null || last.hasBackReference()) { last = new Pair(); pairs.addLast(last); } return last; }
private void clearUnusedBlocksAndPairs() { clearUnusedBlocks(); clearUnusedPairs(); }
/** * Compresses all remaining data and writes it to the stream, * doesn't close the underlying stream. * @throws IOException if an error occurs */ public void finish() throws IOException { if (!finished) { if (currentIndex > 0) { flushBlock(); } writeTrailer(); finished = true; } }
private void writeFinalLiteralBlock() throws IOException { rewriteLastPairs(); for (Pair p : pairs) { if (!p.hasBeenWritten()) { p.writeTo(os); } } pairs.clear(); }
private int readOnce(byte[] b, int off, int len) throws IOException { if (inUncompressed) { int cnt = currentBlock.read(b, off, len); count(cnt); return cnt; } BlockLZ4CompressorInputStream l = (BlockLZ4CompressorInputStream) currentBlock; long before = l.getBytesRead(); int cnt = currentBlock.read(b, off, len); count(l.getBytesRead() - before); return cnt; }
/** * Creates an XXHash32 instance. * @param seed the seed to use */ public XXHash32(int seed) { this.seed = seed; initializeState(); }
boolean canBeWritten(int lengthOfBlocksAfterThisPair) { return hasBackReference() && lengthOfBlocksAfterThisPair >= MIN_OFFSET_OF_LAST_BACK_REFERENCE + MIN_BACK_REFERENCE_LENGTH; } int length() {
@Override public void write(int b) throws IOException { oneByte[0] = (byte) (b & 0xff); write(oneByte); }
@Override public void update(int b) { oneByte[0] = (byte) (b & 0xff); update(oneByte, 0, 1); }
int length() { return literalLength() + brLength; } private boolean hasBeenWritten() {
private void maybeFinishCurrentBlock() throws IOException { if (currentBlock != null) { currentBlock.close(); currentBlock = null; if (expectBlockChecksum) { verifyChecksum(blockHash, "block"); blockHash.reset(); } } }
@Override public void reset() { initializeState(); totalLen = 0; pos = 0; }