diff --git a/src/java/net/jpountz/lz4/LZ4BlockInputStream.java b/src/java/net/jpountz/lz4/LZ4BlockInputStream.java index 23fd5e3..53c6b9e 100644 --- a/src/java/net/jpountz/lz4/LZ4BlockInputStream.java +++ b/src/java/net/jpountz/lz4/LZ4BlockInputStream.java @@ -115,7 +115,7 @@ public LZ4BlockInputStream(InputStream in, LZ4FastDecompressor decompressor) { * @see StreamingXXHash32#asChecksum() */ public LZ4BlockInputStream(InputStream in, boolean stopOnEmptyBlock) { - this(in, LZ4Factory.fastestInstance().fastDecompressor(), XXHashFactory.fastestInstance().newStreamingHash32(DEFAULT_SEED).asChecksum(), stopOnEmptyBlock); + this(in, LZ4Factory.fastestInstance().fastDecompressor(), new LZ4BlockOutputStream.Drop4BitsChecksum(XXHashFactory.fastestInstance().newStreamingHash32(DEFAULT_SEED).asChecksum()), stopOnEmptyBlock); } /** diff --git a/src/java/net/jpountz/lz4/LZ4BlockOutputStream.java b/src/java/net/jpountz/lz4/LZ4BlockOutputStream.java index 623eb1c..898adb2 100644 --- a/src/java/net/jpountz/lz4/LZ4BlockOutputStream.java +++ b/src/java/net/jpountz/lz4/LZ4BlockOutputStream.java @@ -55,6 +55,34 @@ public class LZ4BlockOutputStream extends FilterOutputStream { static final int DEFAULT_SEED = 0x9747b28c; + /** + * This class is for the backward-compatibility before https://github.com/lz4/lz4-java/pull/181. + */ + static class Drop4BitsChecksum implements Checksum { + + private Checksum checksum; + + Drop4BitsChecksum(Checksum checksum) { + this.checksum = checksum; + } + + @Override public void update(int b) { + checksum.update(b); + } + + @Override public void update(byte[] b, int off, int len) { + checksum.update(b, off, len); + } + + @Override public long getValue() { + return checksum.getValue() & 0x0FFFFFFFL; + } + + @Override public void reset() { + checksum.reset(); + } + } + private static int compressionLevel(int blockSize) { if (blockSize < MIN_BLOCK_SIZE) { throw new IllegalArgumentException("blockSize must be >= " + MIN_BLOCK_SIZE + ", got " + blockSize); @@ -122,7 +150,7 @@ public LZ4BlockOutputStream(OutputStream out, int blockSize, LZ4Compressor compr * @see StreamingXXHash32#asChecksum() */ public LZ4BlockOutputStream(OutputStream out, int blockSize, LZ4Compressor compressor) { - this(out, blockSize, compressor, XXHashFactory.fastestInstance().newStreamingHash32(DEFAULT_SEED).asChecksum(), false); + this(out, blockSize, compressor, new Drop4BitsChecksum(XXHashFactory.fastestInstance().newStreamingHash32(DEFAULT_SEED).asChecksum()), false); } /** diff --git a/src/java/net/jpountz/xxhash/StreamingXXHash32.java b/src/java/net/jpountz/xxhash/StreamingXXHash32.java index 8143433..eb5f608 100644 --- a/src/java/net/jpountz/xxhash/StreamingXXHash32.java +++ b/src/java/net/jpountz/xxhash/StreamingXXHash32.java @@ -103,7 +103,7 @@ public final Checksum asChecksum() { @Override public long getValue() { - return StreamingXXHash32.this.getValue() & 0xFFFFFFFL; + return StreamingXXHash32.this.getValue() & 0xFFFFFFFFL; } @Override