static void checkChecksum(ByteBufChecksum checksum, ByteBuf uncompressed, int currentChecksum) { checksum.reset(); checksum.update(uncompressed, uncompressed.readerIndex(), uncompressed.readableBytes()); final int checksumResult = (int) checksum.getValue(); if (checksumResult != currentChecksum) { throw new DecompressionException(String.format( "stream corrupted: mismatching checksum: %d (expected: %d)", checksumResult, currentChecksum)); } }
/** * Creates a new customizable LZ4 decoder. * * @param factory user customizable {@link LZ4Factory} instance * which may be JNI bindings to the original C implementation, a pure Java implementation * or a Java implementation that uses the {@link sun.misc.Unsafe} * @param checksum the {@link Checksum} instance to use to check data for integrity. * You may set {@code null} if you do not want to validate checksum of each block */ public Lz4FrameDecoder(LZ4Factory factory, Checksum checksum) { if (factory == null) { throw new NullPointerException("factory"); } decompressor = factory.fastDecompressor(); this.checksum = checksum == null ? null : ByteBufChecksum.wrapChecksum(checksum); }
crc.update(magic0); crc.update(magic1); crc.update(method); crc.update(flags); crc.update(in, in.readerIndex(), 4); in.skipBytes(4); crc.update(in.readUnsignedByte()); // extra flags crc.update(in.readUnsignedByte()); // operating system crc.update(xlen1); crc.update(xlen2); crc.update(in, in.readerIndex(), xlen); in.skipBytes(xlen); crc.update(b); if (b == 0x00) { break; crc.update(b); if (b == 0x00) { break; crc.reset(); gzipState = GzipState.HEADER_END;
@Override public boolean process(byte value) throws Exception { update(value); return true; } };
private void verifyCrc(ByteBuf in) { long crcValue = 0; for (int i = 0; i < 4; ++i) { crcValue |= (long) in.readUnsignedByte() << i * 8; } long readCrc = crc.getValue(); if (crcValue != readCrc) { throw new DecompressionException( "CRC value mismatch. Expected: " + crcValue + ", Got: " + readCrc); } }
crc.update(magic0); crc.update(magic1); crc.update(method); crc.update(flags); crc.update(in, in.readerIndex(), 4); in.skipBytes(4); crc.update(in.readUnsignedByte()); // extra flags crc.update(in.readUnsignedByte()); // operating system crc.update(xlen1); crc.update(xlen2); crc.update(in, in.readerIndex(), xlen); in.skipBytes(xlen); crc.update(b); if (b == 0x00) { break; crc.update(b); if (b == 0x00) { break; crc.reset(); gzipState = GzipState.HEADER_END;
@Override public boolean process(byte value) throws Exception { update(value); return true; } };
private void verifyCrc(ByteBuf in) { long crcValue = 0; for (int i = 0; i < 4; ++i) { crcValue |= (long) in.readUnsignedByte() << i * 8; } long readCrc = crc.getValue(); if (crcValue != readCrc) { throw new DecompressionException( "CRC value mismatch. Expected: " + crcValue + ", Got: " + readCrc); } }
static void checkChecksum(ByteBufChecksum checksum, ByteBuf uncompressed, int currentChecksum) { checksum.reset(); checksum.update(uncompressed, uncompressed.readerIndex(), uncompressed.readableBytes()); final int checksumResult = (int) checksum.getValue(); if (checksumResult != currentChecksum) { throw new DecompressionException(String.format( "stream corrupted: mismatching checksum: %d (expected: %d)", checksumResult, currentChecksum)); } }
crc.update(magic0); crc.update(magic1); crc.update(method); crc.update(flags); crc.update(in, in.readerIndex(), 4); in.skipBytes(4); crc.update(in.readUnsignedByte()); // extra flags crc.update(in.readUnsignedByte()); // operating system crc.update(xlen1); crc.update(xlen2); crc.update(in, in.readerIndex(), xlen); in.skipBytes(xlen); crc.update(b); if (b == 0x00) { break; crc.update(b); if (b == 0x00) { break; crc.reset(); gzipState = GzipState.HEADER_END;
private JdkZlibDecoder(ZlibWrapper wrapper, byte[] dictionary, boolean decompressConcatenated) { if (wrapper == null) { throw new NullPointerException("wrapper"); } this.decompressConcatenated = decompressConcatenated; switch (wrapper) { case GZIP: inflater = new Inflater(true); crc = ByteBufChecksum.wrapChecksum(new CRC32()); break; case NONE: inflater = new Inflater(true); crc = null; break; case ZLIB: inflater = new Inflater(); crc = null; break; case ZLIB_OR_NONE: // Postpone the decision until decode(...) is called. decideZlibOrNone = true; crc = null; break; default: throw new IllegalArgumentException("Only GZIP or ZLIB is supported, but you used " + wrapper); } this.dictionary = dictionary; }
@Override public boolean process(byte value) throws Exception { update(value); return true; } };
private void verifyCrc(ByteBuf in) { long crcValue = 0; for (int i = 0; i < 4; ++i) { crcValue |= (long) in.readUnsignedByte() << i * 8; } long readCrc = crc.getValue(); if (crcValue != readCrc) { throw new DecompressionException( "CRC value mismatch. Expected: " + crcValue + ", Got: " + readCrc); } }
static void checkChecksum(ByteBufChecksum checksum, ByteBuf uncompressed, int currentChecksum) { checksum.reset(); checksum.update(uncompressed, uncompressed.readerIndex(), uncompressed.readableBytes()); final int checksumResult = (int) checksum.getValue(); if (checksumResult != currentChecksum) { throw new DecompressionException(String.format( "stream corrupted: mismatching checksum: %d (expected: %d)", checksumResult, currentChecksum)); } }
/** * Creates a new customizable LZ4 decoder. * * @param factory user customizable {@link LZ4Factory} instance * which may be JNI bindings to the original C implementation, a pure Java implementation * or a Java implementation that uses the {@link sun.misc.Unsafe} * @param checksum the {@link Checksum} instance to use to check data for integrity. * You may set {@code null} if you do not want to validate checksum of each block */ public Lz4FrameDecoder(LZ4Factory factory, Checksum checksum) { if (factory == null) { throw new NullPointerException("factory"); } decompressor = factory.fastDecompressor(); this.checksum = checksum == null ? null : ByteBufChecksum.wrapChecksum(checksum); }
/** * @see #update(byte[], int, int) */ public void update(ByteBuf b, int off, int len) { if (b.hasArray()) { update(b.array(), b.arrayOffset() + off, len); } else { b.forEachByte(off, len, updateProcessor); } }
private void verifyCrc(ByteBuf in) { long crcValue = 0; for (int i = 0; i < 4; ++i) { crcValue |= (long) in.readUnsignedByte() << i * 8; } long readCrc = crc.getValue(); if (crcValue != readCrc) { throw new DecompressionException( "CRC value mismatch. Expected: " + crcValue + ", Got: " + readCrc); } }