diff --git a/src/build/source_templates/xxhash64_streaming.template b/src/build/source_templates/xxhash64_streaming.template index 2789ae0a..205d5ff7 100644 --- a/src/build/source_templates/xxhash64_streaming.template +++ b/src/build/source_templates/xxhash64_streaming.template @@ -58,7 +58,7 @@ final class StreamingXXHash64Java${type} extends AbstractStreamingXXHash64Java { int off = 0; while (off <= memSize - 8) { long k1 = readLongLE(memory, off); - k1 *= PRIME64_2; k1 = rotateLeft(k1, 31); k1 *= PRIME64_1; h64 ^= k1; + k1 *= PRIME64_2; k1 = rotateLeft(k1, 31); k1 *= PRIME64_1; h64 ^= k1; h64 = rotateLeft(h64, 27) * PRIME64_1 + PRIME64_4; off += 8; } diff --git a/src/java-unsafe/net/jpountz/lz4/LZ4UnsafeUtils.java b/src/java-unsafe/net/jpountz/lz4/LZ4UnsafeUtils.java index 36e8f59b..1eef29c1 100644 --- a/src/java-unsafe/net/jpountz/lz4/LZ4UnsafeUtils.java +++ b/src/java-unsafe/net/jpountz/lz4/LZ4UnsafeUtils.java @@ -55,34 +55,34 @@ static void wildArraycopy(byte[] src, int srcOff, byte[] dest, int destOff, int static void wildIncrementalCopy(byte[] dest, int matchOff, int dOff, int matchCopyEnd) { if (dOff - matchOff < 4) { for (int i = 0; i < 4; ++i) { - writeByte(dest, dOff+i, readByte(dest, matchOff+i)); + writeByte(dest, dOff + i, readByte(dest, matchOff + i)); } dOff += 4; matchOff += 4; int dec = 0; assert dOff >= matchOff && dOff - matchOff < 8; switch (dOff - matchOff) { - case 1: - matchOff -= 3; - break; - case 2: - matchOff -= 2; - break; - case 3: - matchOff -= 3; - dec = -1; - break; - case 5: - dec = 1; - break; - case 6: - dec = 2; - break; - case 7: - dec = 3; - break; - default: - break; + case 1: + matchOff -= 3; + break; + case 2: + matchOff -= 2; + break; + case 3: + matchOff -= 3; + dec = -1; + break; + case 5: + dec = 1; + break; + case 6: + dec = 2; + break; + case 7: + dec = 3; + break; + default: + break; } writeInt(dest, dOff, readInt(dest, matchOff)); dOff += 4; diff --git a/src/java-unsafe/net/jpountz/util/UnsafeUtils.java b/src/java-unsafe/net/jpountz/util/UnsafeUtils.java index 1af5cb0d..d6016576 100644 --- a/src/java-unsafe/net/jpountz/util/UnsafeUtils.java +++ b/src/java-unsafe/net/jpountz/util/UnsafeUtils.java @@ -33,7 +33,7 @@ public enum UnsafeUtils { private static final int INT_ARRAY_SCALE; private static final long SHORT_ARRAY_OFFSET; private static final int SHORT_ARRAY_SCALE; - + static { try { Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); diff --git a/src/java/net/jpountz/lz4/LZ4BlockOutputStream.java b/src/java/net/jpountz/lz4/LZ4BlockOutputStream.java index 623eb1c6..96e0a360 100644 --- a/src/java/net/jpountz/lz4/LZ4BlockOutputStream.java +++ b/src/java/net/jpountz/lz4/LZ4BlockOutputStream.java @@ -228,7 +228,7 @@ private void flushBufferedData() throws IOException { /** * Flushes this compressed {@link OutputStream}. - * + *

* If the stream has been created with syncFlush=true, pending * data will be compressed and appended to the underlying {@link OutputStream} * before calling {@link OutputStream#flush()} on the underlying stream. diff --git a/src/java/net/jpountz/lz4/LZ4ByteBufferUtils.java b/src/java/net/jpountz/lz4/LZ4ByteBufferUtils.java index 9fe63d7d..f6c57168 100644 --- a/src/java/net/jpountz/lz4/LZ4ByteBufferUtils.java +++ b/src/java/net/jpountz/lz4/LZ4ByteBufferUtils.java @@ -36,6 +36,7 @@ enum LZ4ByteBufferUtils { ; + static int hash(ByteBuffer buf, int i) { return LZ4Utils.hash(readInt(buf, i)); } @@ -57,34 +58,34 @@ static void safeIncrementalCopy(ByteBuffer dest, int matchOff, int dOff, int mat static void wildIncrementalCopy(ByteBuffer dest, int matchOff, int dOff, int matchCopyEnd) { if (dOff - matchOff < 4) { for (int i = 0; i < 4; ++i) { - writeByte(dest, dOff+i, readByte(dest, matchOff+i)); + writeByte(dest, dOff + i, readByte(dest, matchOff + i)); } dOff += 4; matchOff += 4; int dec = 0; assert dOff >= matchOff && dOff - matchOff < 8; switch (dOff - matchOff) { - case 1: - matchOff -= 3; - break; - case 2: - matchOff -= 2; - break; - case 3: - matchOff -= 3; - dec = -1; - break; - case 5: - dec = 1; - break; - case 6: - dec = 2; - break; - case 7: - dec = 3; - break; - default: - break; + case 1: + matchOff -= 3; + break; + case 2: + matchOff -= 2; + break; + case 3: + matchOff -= 3; + dec = -1; + break; + case 5: + dec = 1; + break; + case 6: + dec = 2; + break; + case 7: + dec = 3; + break; + default: + break; } writeInt(dest, dOff, readInt(dest, matchOff)); dOff += 4; diff --git a/src/java/net/jpountz/lz4/LZ4Compressor.java b/src/java/net/jpountz/lz4/LZ4Compressor.java index e9e72b3b..087f47de 100644 --- a/src/java/net/jpountz/lz4/LZ4Compressor.java +++ b/src/java/net/jpountz/lz4/LZ4Compressor.java @@ -41,7 +41,7 @@ public final int maxCompressedLength(int length) { * Compresses src[srcOff:srcOff+srcLen] into * dest[destOff:destOff+maxDestLen] and returns the compressed * length. - * + *

* This method will throw a {@link LZ4Exception} if this compressor is unable * to compress the input into less than maxDestLen bytes. To * prevent this exception to be thrown, you should make sure that @@ -62,12 +62,12 @@ public final int maxCompressedLength(int length) { * Compresses src[srcOff:srcOff+srcLen] into * dest[destOff:destOff+maxDestLen] and returns the compressed * length. - * + *

* This method will throw a {@link LZ4Exception} if this compressor is unable * to compress the input into less than maxDestLen bytes. To * prevent this exception to be thrown, you should make sure that * maxDestLen >= maxCompressedLength(srcLen). - * + *

* {@link ByteBuffer} positions remain unchanged. * * @param src the source data diff --git a/src/java/net/jpountz/lz4/LZ4CompressorWithLength.java b/src/java/net/jpountz/lz4/LZ4CompressorWithLength.java index e52ae1ee..3a2d566e 100644 --- a/src/java/net/jpountz/lz4/LZ4CompressorWithLength.java +++ b/src/java/net/jpountz/lz4/LZ4CompressorWithLength.java @@ -43,17 +43,17 @@ public LZ4CompressorWithLength(LZ4Compressor compressor) { } private void putOriginalLength(byte[] dest, int destOff, int originalLength) { - dest[destOff] = (byte)originalLength; - dest[destOff + 1] = (byte)(originalLength >> 8); - dest[destOff + 2] = (byte)(originalLength >> 16); - dest[destOff + 3] = (byte)(originalLength >> 24); + dest[destOff] = (byte) originalLength; + dest[destOff + 1] = (byte) (originalLength >> 8); + dest[destOff + 2] = (byte) (originalLength >> 16); + dest[destOff + 3] = (byte) (originalLength >> 24); } private void putOriginalLength(ByteBuffer dest, int destOff, int originalLength) { - dest.put(destOff, (byte)originalLength); - dest.put(destOff + 1, (byte)(originalLength >> 8)); - dest.put(destOff + 2, (byte)(originalLength >> 16)); - dest.put(destOff + 3, (byte)(originalLength >> 24)); + dest.put(destOff, (byte) originalLength); + dest.put(destOff + 1, (byte) (originalLength >> 8)); + dest.put(destOff + 2, (byte) (originalLength >> 16)); + dest.put(destOff + 3, (byte) (originalLength >> 24)); } /** @@ -137,7 +137,7 @@ public int compress(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff * Compresses src[srcOff:srcOff+srcLen] into * dest[destOff:destOff+maxDestLen] and returns the compressed * length. - * + *

* This method will throw a {@link LZ4Exception} if this compressor is unable * to compress the input into less than maxDestLen bytes. To * prevent this exception to be thrown, you should make sure that @@ -176,12 +176,12 @@ public void compress(ByteBuffer src, ByteBuffer dest) { * Compresses src[srcOff:srcOff+srcLen] into * dest[destOff:destOff+maxDestLen] and returns the compressed * length. - * + *

* This method will throw a {@link LZ4Exception} if this compressor is unable * to compress the input into less than maxDestLen bytes. To * prevent this exception to be thrown, you should make sure that * maxDestLen >= maxCompressedLength(srcLen). - * + *

* {@link ByteBuffer} positions remain unchanged. * * @param src the source data diff --git a/src/java/net/jpountz/lz4/LZ4Constants.java b/src/java/net/jpountz/lz4/LZ4Constants.java index 5f776d03..3f33b37c 100644 --- a/src/java/net/jpountz/lz4/LZ4Constants.java +++ b/src/java/net/jpountz/lz4/LZ4Constants.java @@ -20,8 +20,8 @@ enum LZ4Constants { ; - static final int DEFAULT_COMPRESSION_LEVEL = 8+1; - static final int MAX_COMPRESSION_LEVEL = 16+1; + static final int DEFAULT_COMPRESSION_LEVEL = 8 + 1; + static final int MAX_COMPRESSION_LEVEL = 16 + 1; static final int MEMORY_USAGE = 14; static final int NOT_COMPRESSIBLE_DETECTION_LEVEL = 6; diff --git a/src/java/net/jpountz/lz4/LZ4DecompressorWithLength.java b/src/java/net/jpountz/lz4/LZ4DecompressorWithLength.java index a89413cd..ec371020 100644 --- a/src/java/net/jpountz/lz4/LZ4DecompressorWithLength.java +++ b/src/java/net/jpountz/lz4/LZ4DecompressorWithLength.java @@ -229,7 +229,8 @@ public void decompress(ByteBuffer src, ByteBuffer dest) { } } - /** When {@link LZ4FastDecompressor} was specified to the constructor, + /** + * When {@link LZ4FastDecompressor} was specified to the constructor, * decompresses src[srcOff:] into dest[destOff:] * and returns the number of bytes read from src, and * when {@link LZ4SafeDecompressor} was specified to the constructor, diff --git a/src/java/net/jpountz/lz4/LZ4Factory.java b/src/java/net/jpountz/lz4/LZ4Factory.java index e4f2e97f..6110b2cc 100644 --- a/src/java/net/jpountz/lz4/LZ4Factory.java +++ b/src/java/net/jpountz/lz4/LZ4Factory.java @@ -23,6 +23,7 @@ import net.jpountz.util.Native; import net.jpountz.util.Utils; + import static net.jpountz.lz4.LZ4Constants.DEFAULT_COMPRESSION_LEVEL; import static net.jpountz.lz4.LZ4Constants.MAX_COMPRESSION_LEVEL; @@ -231,22 +232,22 @@ private static T classInstance(String cls) throws NoSuchFieldException, Secu private final LZ4Compressor highCompressor; private final LZ4FastDecompressor fastDecompressor; private final LZ4SafeDecompressor safeDecompressor; - private final LZ4Compressor[] highCompressors = new LZ4Compressor[MAX_COMPRESSION_LEVEL+1]; + private final LZ4Compressor[] highCompressors = new LZ4Compressor[MAX_COMPRESSION_LEVEL + 1]; private LZ4Factory(String impl, boolean insecureFastDecompressor) throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, NoSuchMethodException, InstantiationException, InvocationTargetException { this.impl = impl; fastCompressor = classInstance("net.jpountz.lz4.LZ4" + impl + "Compressor"); highCompressor = classInstance("net.jpountz.lz4.LZ4HC" + impl + "Compressor"); if (insecureFastDecompressor) { - fastDecompressor = classInstance("net.jpountz.lz4.LZ4" + impl + "FastDecompressor"); + fastDecompressor = classInstance("net.jpountz.lz4.LZ4" + impl + "FastDecompressor"); } else { - fastDecompressor = LZ4JavaSafeFastDecompressor.INSTANCE; + fastDecompressor = LZ4JavaSafeFastDecompressor.INSTANCE; } safeDecompressor = classInstance("net.jpountz.lz4.LZ4" + impl + "SafeDecompressor"); Constructor highConstructor = highCompressor.getClass().getDeclaredConstructor(int.class); highCompressors[DEFAULT_COMPRESSION_LEVEL] = highCompressor; - for(int level = 1; level <= MAX_COMPRESSION_LEVEL; level++) { - if(level == DEFAULT_COMPRESSION_LEVEL) continue; + for (int level = 1; level <= MAX_COMPRESSION_LEVEL; level++) { + if (level == DEFAULT_COMPRESSION_LEVEL) continue; highCompressors[level] = highConstructor.newInstance(level); } @@ -310,7 +311,7 @@ public LZ4Compressor highCompressor() { * {@link #fastCompressor()} and is slower but compresses more efficiently. */ public LZ4Compressor highCompressor(int compressionLevel) { - if(compressionLevel > MAX_COMPRESSION_LEVEL) { + if (compressionLevel > MAX_COMPRESSION_LEVEL) { compressionLevel = MAX_COMPRESSION_LEVEL; } else if (compressionLevel < 1) { compressionLevel = DEFAULT_COMPRESSION_LEVEL; diff --git a/src/java/net/jpountz/lz4/LZ4FastDecompressor.java b/src/java/net/jpountz/lz4/LZ4FastDecompressor.java index e60e84ae..c6008863 100644 --- a/src/java/net/jpountz/lz4/LZ4FastDecompressor.java +++ b/src/java/net/jpountz/lz4/LZ4FastDecompressor.java @@ -34,7 +34,8 @@ */ public abstract class LZ4FastDecompressor implements LZ4Decompressor { - /** Decompresses src[srcOff:] into dest[destOff:destOff+destLen] + /** + * Decompresses src[srcOff:] into dest[destOff:destOff+destLen] * and returns the number of bytes read from src. * destLen must be exactly the size of the decompressed data. * @@ -47,7 +48,8 @@ public abstract class LZ4FastDecompressor implements LZ4Decompressor { */ public abstract int decompress(byte[] src, int srcOff, byte[] dest, int destOff, int destLen); - /** Decompresses src[srcOff:] into dest[destOff:destOff+destLen] + /** + * Decompresses src[srcOff:] into dest[destOff:destOff+destLen] * and returns the number of bytes read from src. * destLen must be exactly the size of the decompressed data. * The positions and limits of the {@link ByteBuffer}s remain unchanged. diff --git a/src/java/net/jpountz/lz4/LZ4FrameInputStream.java b/src/java/net/jpountz/lz4/LZ4FrameInputStream.java index 0c1f18ee..a86af764 100644 --- a/src/java/net/jpountz/lz4/LZ4FrameInputStream.java +++ b/src/java/net/jpountz/lz4/LZ4FrameInputStream.java @@ -70,7 +70,7 @@ public class LZ4FrameInputStream extends FilterInputStream { * @param in the stream to decompress * @throws IOException if an I/O error occurs * - * @see #LZ4FrameInputStream(InputStream, LZ4SafeDecompressor, XXHash32) + * @see #LZ4FrameInputStream(InputStream, LZ4SafeDecompressor, XXHash32) * @see LZ4Factory#fastestInstance() * @see XXHashFactory#fastestInstance() */ @@ -85,7 +85,7 @@ public LZ4FrameInputStream(InputStream in) throws IOException { * @param readSingleFrame whether read is stopped after the first non-skippable frame * @throws IOException if an I/O error occurs * - * @see #LZ4FrameInputStream(InputStream, LZ4SafeDecompressor, XXHash32) + * @see #LZ4FrameInputStream(InputStream, LZ4SafeDecompressor, XXHash32) * @see LZ4Factory#fastestInstance() * @see XXHashFactory#fastestInstance() */ @@ -102,9 +102,9 @@ public LZ4FrameInputStream(InputStream in, boolean readSingleFrame) throws IOExc * @param checksum the hash function to use * @throws IOException if an I/O error occurs * - * @see #LZ4FrameInputStream(InputStream, LZ4SafeDecompressor, XXHash32, boolean) + * @see #LZ4FrameInputStream(InputStream, LZ4SafeDecompressor, XXHash32, boolean) */ - public LZ4FrameInputStream(InputStream in, LZ4SafeDecompressor decompressor, XXHash32 checksum) throws IOException { + public LZ4FrameInputStream(InputStream in, LZ4SafeDecompressor decompressor, XXHash32 checksum) throws IOException { this(in, decompressor, checksum, false); } @@ -117,7 +117,7 @@ public LZ4FrameInputStream(InputStream in, LZ4SafeDecompressor decompressor, XX * @param readSingleFrame whether read is stopped after the first non-skippable frame * @throws IOException if an I/O error occurs */ - public LZ4FrameInputStream(InputStream in, LZ4SafeDecompressor decompressor, XXHash32 checksum, boolean readSingleFrame) throws IOException { + public LZ4FrameInputStream(InputStream in, LZ4SafeDecompressor decompressor, XXHash32 checksum, boolean readSingleFrame) throws IOException { super(in); this.decompressor = decompressor; this.checksum = checksum; @@ -128,6 +128,7 @@ public LZ4FrameInputStream(InputStream in, LZ4SafeDecompressor decompressor, XX /** * Try and load in the next valid frame info. This will skip over skippable frames. + * * @return True if a frame was loaded. False if there are no more frames in the stream. * @throws IOException On input stream read exception */ @@ -135,8 +136,8 @@ private boolean nextFrameInfo() throws IOException { while (true) { int size = 0; do { - final int mySize = in.read(readNumberBuff.array(), size, LZ4FrameOutputStream.INTEGER_BYTES - size); - if (mySize < 0) { + final int mySize = in.read(readNumberBuff.array(), size, LZ4FrameOutputStream.INTEGER_BYTES - size); + if (mySize < 0) { if (firstFrameHeaderRead) { if (size > 0) { throw new IOException(PREMATURE_EOS); @@ -146,17 +147,17 @@ private boolean nextFrameInfo() throws IOException { } else { throw new IOException(PREMATURE_EOS); } - } - size += mySize; + } + size += mySize; } while (size < LZ4FrameOutputStream.INTEGER_BYTES); final int magic = readNumberBuff.getInt(0); if (magic == LZ4FrameOutputStream.MAGIC) { - readHeader(); - return true; + readHeader(); + return true; } else if ((magic >>> 4) == (MAGIC_SKIPPABLE_BASE >>> 4)) { - skippableFrame(); + skippableFrame(); } else { - throw new IOException(NOT_SUPPORTED); + throw new IOException(NOT_SUPPORTED); } } } @@ -191,10 +192,10 @@ private void readHeader() throws IOException { throw new IOException(PREMATURE_EOS); } - final byte flgByte = (byte)(flgRead & 0xFF); + final byte flgByte = (byte) (flgRead & 0xFF); final LZ4FrameOutputStream.FLG flg = LZ4FrameOutputStream.FLG.fromByte(flgByte); headerBuffer.put(flgByte); - final byte bdByte = (byte)(bdRead & 0xFF); + final byte bdByte = (byte) (bdRead & 0xFF); final LZ4FrameOutputStream.BD bd = LZ4FrameOutputStream.BD.fromByte(bdByte); headerBuffer.put(bdByte); @@ -213,7 +214,7 @@ private void readHeader() throws IOException { throw new IOException(PREMATURE_EOS); } - if (hash != (byte)(expectedHash & 0xFF)) { + if (hash != (byte) (expectedHash & 0xFF)) { throw new IOException(DESCRIPTOR_HASH_MISMATCH); } @@ -271,7 +272,7 @@ private void readBlock() throws IOException { } } if (frameInfo.isEnabled(LZ4FrameOutputStream.FLG.Bits.CONTENT_SIZE) && expectedContentSize != totalContentSize) { - throw new IOException("Size check mismatch"); + throw new IOException("Size check mismatch"); } frameInfo.finish(); return; @@ -329,13 +330,13 @@ public int read() throws IOException { if (firstFrameHeaderRead && readSingleFrame) { return -1; } - if (!nextFrameInfo()) { - return -1; - } + if (!nextFrameInfo()) { + return -1; + } } readBlock(); } - return (int)buffer.get() & 0xFF; + return (int) buffer.get() & 0xFF; } @Override @@ -348,9 +349,9 @@ public int read(byte[] b, int off, int len) throws IOException { if (firstFrameHeaderRead && readSingleFrame) { return -1; } - if (!nextFrameInfo()) { - return -1; - } + if (!nextFrameInfo()) { + return -1; + } } readBlock(); } @@ -369,14 +370,14 @@ public long skip(long n) throws IOException { if (firstFrameHeaderRead && readSingleFrame) { return 0; } - if (!nextFrameInfo()) { - return 0; - } + if (!nextFrameInfo()) { + return 0; + } } readBlock(); } n = Math.min(n, buffer.remaining()); - buffer.position(buffer.position() + (int)n); + buffer.position(buffer.position() + (int) n); return n; } @@ -413,7 +414,7 @@ public boolean markSupported() { * @return the expected content size, or -1L if no expected content size is set in the frame. * @throws IOException On input stream read exception * - * @see #LZ4FrameInputStream(InputStream, LZ4SafeDecompressor, XXHash32, boolean) + * @see #LZ4FrameInputStream(InputStream, LZ4SafeDecompressor, XXHash32, boolean) */ public long getExpectedContentSize() throws IOException { if (!readSingleFrame) { @@ -421,7 +422,7 @@ public long getExpectedContentSize() throws IOException { } if (!firstFrameHeaderRead) { if (!nextFrameInfo()) { - return -1L; + return -1L; } } return expectedContentSize; @@ -436,9 +437,9 @@ public long getExpectedContentSize() throws IOException { public boolean isExpectedContentSizeDefined() throws IOException { if (readSingleFrame) { if (!firstFrameHeaderRead) { - if (!nextFrameInfo()) { - return false; - } + if (!nextFrameInfo()) { + return false; + } } return expectedContentSize >= 0; } else { diff --git a/src/java/net/jpountz/lz4/LZ4FrameOutputStream.java b/src/java/net/jpountz/lz4/LZ4FrameOutputStream.java index a8382fde..42a85463 100644 --- a/src/java/net/jpountz/lz4/LZ4FrameOutputStream.java +++ b/src/java/net/jpountz/lz4/LZ4FrameOutputStream.java @@ -64,14 +64,17 @@ public class LZ4FrameOutputStream extends FilterOutputStream { public static enum BLOCKSIZE { SIZE_64KB(4), SIZE_256KB(5), SIZE_1MB(6), SIZE_4MB(7); private final int indicator; + BLOCKSIZE(int indicator) { this.indicator = indicator; } + public int getIndicator() { return this.indicator; } + public static BLOCKSIZE valueOf(int indicator) { - switch(indicator) { + switch (indicator) { case 7: return SIZE_4MB; case 6: return SIZE_1MB; case 5: return SIZE_256KB; @@ -117,7 +120,7 @@ public LZ4FrameOutputStream(OutputStream out, BLOCKSIZE blockSize, FLG.Bits... b */ public LZ4FrameOutputStream(OutputStream out, BLOCKSIZE blockSize, long knownSize, FLG.Bits... bits) throws IOException { this(out, blockSize, knownSize, LZ4Factory.fastestInstance().fastCompressor(), - XXHashFactory.fastestInstance().hash32(), bits); + XXHashFactory.fastestInstance().hash32(), bits); } /** @@ -322,6 +325,7 @@ public enum Bits { BLOCK_INDEPENDENCE(5); private final int position; + Bits(int position) { this.position = position; } @@ -345,12 +349,12 @@ private FLG(int version, byte b) { } public static FLG fromByte(byte flg) { - final byte versionMask = (byte)(flg & (3 << 6)); + final byte versionMask = (byte) (flg & (3 << 6)); return new FLG(versionMask >>> 6, (byte) (flg ^ versionMask)); } public byte toByte() { - return (byte)(bitSet.toByteArray()[0] | ((version & 3) << 6)); + return (byte) (bitSet.toByteArray()[0] | ((version & 3) << 6)); } private void validate() { diff --git a/src/java/net/jpountz/lz4/LZ4SafeDecompressor.java b/src/java/net/jpountz/lz4/LZ4SafeDecompressor.java index 71938c9a..92792c34 100644 --- a/src/java/net/jpountz/lz4/LZ4SafeDecompressor.java +++ b/src/java/net/jpountz/lz4/LZ4SafeDecompressor.java @@ -140,6 +140,7 @@ public final byte[] decompress(byte[] src, int maxDestLen) { * Decompresses src into dest. src's * {@link ByteBuffer#remaining()} must be exactly the size of the compressed * data. This method moves the positions of the buffers. + * * @param src the compressed data * @param dest the destination buffer to store the decompressed data * @throws LZ4Exception if dest is too small diff --git a/src/java/net/jpountz/lz4/LZ4SafeUtils.java b/src/java/net/jpountz/lz4/LZ4SafeUtils.java index 59bb3dd4..1d62b991 100644 --- a/src/java/net/jpountz/lz4/LZ4SafeUtils.java +++ b/src/java/net/jpountz/lz4/LZ4SafeUtils.java @@ -38,7 +38,7 @@ static int hash64k(byte[] buf, int i) { } static boolean readIntEquals(byte[] buf, int i, int j) { - return buf[i] == buf[j] && buf[i+1] == buf[j+1] && buf[i+2] == buf[j+2] && buf[i+3] == buf[j+3]; + return buf[i] == buf[j] && buf[i + 1] == buf[j + 1] && buf[i + 2] == buf[j + 2] && buf[i + 3] == buf[j + 3]; } static void safeIncrementalCopy(byte[] dest, int matchOff, int dOff, int matchLen) { diff --git a/src/java/net/jpountz/util/ByteBufferUtils.java b/src/java/net/jpountz/util/ByteBufferUtils.java index 72bad9fb..1ab5a133 100644 --- a/src/java/net/jpountz/util/ByteBufferUtils.java +++ b/src/java/net/jpountz/util/ByteBufferUtils.java @@ -104,6 +104,6 @@ public static void checkNotReadOnly(ByteBuffer buffer) { } public static int readShortLE(ByteBuffer buf, int i) { - return (buf.get(i) & 0xFF) | ((buf.get(i+1) & 0xFF) << 8); + return (buf.get(i) & 0xFF) | ((buf.get(i + 1) & 0xFF) << 8); } } diff --git a/src/java/net/jpountz/util/Native.java b/src/java/net/jpountz/util/Native.java index 048dda57..b54c79da 100644 --- a/src/java/net/jpountz/util/Native.java +++ b/src/java/net/jpountz/util/Native.java @@ -53,7 +53,7 @@ private static OS os() { return OS.SOLARIS; } else { throw new UnsupportedOperationException("Unsupported operating system: " - + osName); + + osName); } } @@ -75,22 +75,24 @@ private static void cleanupOldTempLibs() { File dir = new File(tempFolder); File[] tempLibFiles = dir.listFiles(new FilenameFilter() { - private final String searchPattern = "liblz4-java-"; - public boolean accept(File dir, String name) { - return name.startsWith(searchPattern) && !name.endsWith(".lck"); - } - }); - if(tempLibFiles != null) { - for(File tempLibFile : tempLibFiles) { - File lckFile = new File(tempLibFile.getAbsolutePath() + ".lck"); - if(!lckFile.exists()) { - try { - tempLibFile.delete(); - } - catch(SecurityException e) { - System.err.println("Failed to delete old temp lib" + e.getMessage()); - } - } + private final String searchPattern = "liblz4-java-"; + + @Override + public boolean accept(File dir, String name) { + return name.startsWith(searchPattern) && !name.endsWith(".lck"); + } + }); + + if (tempLibFiles != null) { + for (File tempLibFile : tempLibFiles) { + File lckFile = new File(tempLibFile.getAbsolutePath() + ".lck"); + if (!lckFile.exists()) { + try { + tempLibFile.delete(); + } catch (SecurityException e) { + System.err.println("Failed to delete old temp lib: " + e.getMessage()); + } + } } } } @@ -125,14 +127,14 @@ public static synchronized void load() { tempLib = new File(tempLibLock.getAbsolutePath().replaceFirst(".lck$", "")); // copy to tempLib try (FileOutputStream out = new FileOutputStream(tempLib)) { - byte[] buf = new byte[4096]; - while (true) { - int read = is.read(buf); - if (read == -1) { - break; - } - out.write(buf, 0, read); - } + byte[] buf = new byte[4096]; + while (true) { + int read = is.read(buf); + if (read == -1) { + break; + } + out.write(buf, 0, read); + } } System.load(tempLib.getAbsolutePath()); loaded = true; @@ -140,23 +142,23 @@ public static synchronized void load() { throw new ExceptionInInitializerError("Cannot unpack liblz4-java: " + e); } finally { if (!loaded) { - if (tempLib != null && tempLib.exists()) { - if (!tempLib.delete()) { - throw new ExceptionInInitializerError("Cannot unpack liblz4-java / cannot delete a temporary native library " + tempLib); - } - } - if (tempLibLock != null && tempLibLock.exists()) { - if (!tempLibLock.delete()) { - throw new ExceptionInInitializerError("Cannot unpack liblz4-java / cannot delete a temporary lock file " + tempLibLock); - } - } + if (tempLib != null && tempLib.exists()) { + if (!tempLib.delete()) { + throw new ExceptionInInitializerError("Cannot unpack liblz4-java / cannot delete a temporary native library " + tempLib); + } + } + if (tempLibLock != null && tempLibLock.exists()) { + if (!tempLibLock.delete()) { + throw new ExceptionInInitializerError("Cannot unpack liblz4-java / cannot delete a temporary lock file " + tempLibLock); + } + } } else { final String keepEnv = System.getenv("LZ4JAVA_KEEP_TEMP_JNI_LIB"); final String keepProp = System.getProperty("lz4java.jnilib.temp.keep"); if ((keepEnv == null || !keepEnv.equals("true")) && (keepProp == null || !keepProp.equals("true"))) tempLib.deleteOnExit(); - tempLibLock.deleteOnExit(); + tempLibLock.deleteOnExit(); } } } diff --git a/src/java/net/jpountz/util/SafeUtils.java b/src/java/net/jpountz/util/SafeUtils.java index d371688f..7f8449a2 100644 --- a/src/java/net/jpountz/util/SafeUtils.java +++ b/src/java/net/jpountz/util/SafeUtils.java @@ -47,11 +47,11 @@ public static byte readByte(byte[] buf, int i) { } public static int readIntBE(byte[] buf, int i) { - return ((buf[i] & 0xFF) << 24) | ((buf[i+1] & 0xFF) << 16) | ((buf[i+2] & 0xFF) << 8) | (buf[i+3] & 0xFF); + return ((buf[i] & 0xFF) << 24) | ((buf[i + 1] & 0xFF) << 16) | ((buf[i + 2] & 0xFF) << 8) | (buf[i + 3] & 0xFF); } public static int readIntLE(byte[] buf, int i) { - return (buf[i] & 0xFF) | ((buf[i+1] & 0xFF) << 8) | ((buf[i+2] & 0xFF) << 16) | ((buf[i+3] & 0xFF) << 24); + return (buf[i] & 0xFF) | ((buf[i + 1] & 0xFF) << 8) | ((buf[i + 2] & 0xFF) << 16) | ((buf[i + 3] & 0xFF) << 24); } public static int readInt(byte[] buf, int i) { @@ -63,8 +63,8 @@ public static int readInt(byte[] buf, int i) { } public static long readLongLE(byte[] buf, int i) { - return (buf[i] & 0xFFL) | ((buf[i+1] & 0xFFL) << 8) | ((buf[i+2] & 0xFFL) << 16) | ((buf[i+3] & 0xFFL) << 24) - | ((buf[i+4] & 0xFFL) << 32) | ((buf[i+5] & 0xFFL) << 40) | ((buf[i+6] & 0xFFL) << 48) | ((buf[i+7] & 0xFFL) << 56); + return (buf[i] & 0xFFL) | ((buf[i + 1] & 0xFFL) << 8) | ((buf[i + 2] & 0xFFL) << 16) | ((buf[i + 3] & 0xFFL) << 24) + | ((buf[i + 4] & 0xFFL) << 32) | ((buf[i + 5] & 0xFFL) << 40) | ((buf[i + 6] & 0xFFL) << 48) | ((buf[i + 7] & 0xFFL) << 56); } public static void writeShortLE(byte[] buf, int off, int v) { @@ -89,7 +89,7 @@ public static void writeShort(short[] buf, int off, int v) { } public static int readShortLE(byte[] buf, int i) { - return (buf[i] & 0xFF) | ((buf[i+1] & 0xFF) << 8); + return (buf[i] & 0xFF) | ((buf[i + 1] & 0xFF) << 8); } public static int readShort(short[] buf, int off) { diff --git a/src/java/net/jpountz/util/Utils.java b/src/java/net/jpountz/util/Utils.java index bcb9f796..6f805f23 100644 --- a/src/java/net/jpountz/util/Utils.java +++ b/src/java/net/jpountz/util/Utils.java @@ -28,8 +28,8 @@ public enum Utils { static { String arch = System.getProperty("os.arch"); unalignedAccessAllowed = arch.equals("i386") || arch.equals("x86") - || arch.equals("amd64") || arch.equals("x86_64") - || arch.equals("aarch64") || arch.equals("ppc64le"); + || arch.equals("amd64") || arch.equals("x86_64") + || arch.equals("aarch64") || arch.equals("ppc64le"); } public static boolean isUnalignedAccessAllowed() { diff --git a/src/java/net/jpountz/xxhash/XXHash32.java b/src/java/net/jpountz/xxhash/XXHash32.java index 442e38ca..6d4254d6 100644 --- a/src/java/net/jpountz/xxhash/XXHash32.java +++ b/src/java/net/jpountz/xxhash/XXHash32.java @@ -40,7 +40,7 @@ public abstract class XXHash32 { /** * Computes the hash of the given slice of the {@link ByteBuffer}. * {@link ByteBuffer#position() position} and {@link ByteBuffer#limit() limit} - * are not modified. + * are not modified. * * @param buf the input data * @param off the start offset in buf diff --git a/src/java/net/jpountz/xxhash/XXHash64.java b/src/java/net/jpountz/xxhash/XXHash64.java index 32572072..75141e52 100644 --- a/src/java/net/jpountz/xxhash/XXHash64.java +++ b/src/java/net/jpountz/xxhash/XXHash64.java @@ -40,7 +40,7 @@ public abstract class XXHash64 { /** * Computes the hash of the given slice of the {@link ByteBuffer}. * {@link ByteBuffer#position() position} and {@link ByteBuffer#limit() limit} - * are not modified. + * are not modified. * * @param buf the input data * @param off the start offset in buf diff --git a/src/java/net/jpountz/xxhash/XXHashFactory.java b/src/java/net/jpountz/xxhash/XXHashFactory.java index e7a3e9ca..6724eb5b 100644 --- a/src/java/net/jpountz/xxhash/XXHashFactory.java +++ b/src/java/net/jpountz/xxhash/XXHashFactory.java @@ -58,7 +58,7 @@ private static XXHashFactory instance(String impl) { /** * Returns a {@link XXHashFactory} that returns {@link XXHash32} instances that - * are native bindings to the original C API. + * are native bindings to the original C API. *

* Please note that this instance has some traps you should be aware of:

    *
  1. Upon loading this instance, files will be written to the temporary @@ -75,7 +75,7 @@ private static XXHashFactory instance(String impl) { *
* * @return a {@link XXHashFactory} that returns {@link XXHash32} instances that - * are native bindings to the original C API. + * are native bindings to the original C API. */ public static synchronized XXHashFactory nativeInstance() { if (NATIVE_INSTANCE == null) { @@ -86,10 +86,10 @@ public static synchronized XXHashFactory nativeInstance() { /** * Returns a {@link XXHashFactory} that returns {@link XXHash32} instances that - * are written with Java's official API. + * are written with Java's official API. * * @return a {@link XXHashFactory} that returns {@link XXHash32} instances that - * are written with Java's official API. + * are written with Java's official API. */ public static synchronized XXHashFactory safeInstance() { if (JAVA_SAFE_INSTANCE == null) { @@ -100,10 +100,10 @@ public static synchronized XXHashFactory safeInstance() { /** * Returns a {@link XXHashFactory} that returns {@link XXHash32} instances that - * may use {@link sun.misc.Unsafe} to speed up hashing. + * may use {@link sun.misc.Unsafe} to speed up hashing. * * @return a {@link XXHashFactory} that returns {@link XXHash32} instances that - * may use {@link sun.misc.Unsafe} to speed up hashing. + * may use {@link sun.misc.Unsafe} to speed up hashing. */ public static synchronized XXHashFactory unsafeInstance() { if (JAVA_UNSAFE_INSTANCE == null) { diff --git a/src/test/net/jpountz/lz4/AbstractLZ4Test.java b/src/test/net/jpountz/lz4/AbstractLZ4Test.java index e21e3c1a..66c82cba 100644 --- a/src/test/net/jpountz/lz4/AbstractLZ4Test.java +++ b/src/test/net/jpountz/lz4/AbstractLZ4Test.java @@ -54,7 +54,7 @@ public byte[] copyOf(byte[] data, int off, int len) { @Override public int maxCompressedLength(int len) { - return LZ4Utils.maxCompressedLength(len); + return LZ4Utils.maxCompressedLength(len); } @Override @@ -104,7 +104,7 @@ public byte[] copyOf(ByteBuffer data, int off, int len) { @Override public int maxCompressedLength(int len) { - return LZ4Utils.maxCompressedLength(len); + return LZ4Utils.maxCompressedLength(len); } @Override @@ -142,6 +142,7 @@ public int decompress(LZ4SafeDecompressor decompressor, return decompressor.decompress(src, srcOff, srcLen, dest, destOff, maxDestLen); } } + public static final Tester BYTE_ARRAY = new ByteArrayTester(); public static final Tester BYTE_ARRAY_WITH_LENGTH = new ByteArrayTester() { @Override @@ -183,6 +184,7 @@ public int decompress(LZ4SafeDecompressor decompressor, ByteBuffer src, return decompressor.decompress(src, srcOff, srcLen, dest, destOff, maxDestLen); } } + public static final Tester BYTE_BUFFER = new ByteBufferTester(); public static final Tester BYTE_BUFFER_WITH_LENGTH = new ByteBufferTester() { @Override @@ -229,6 +231,7 @@ public int decompress(LZ4SafeDecompressor decompressor, byte[] src, byte[] dest) return decompressor.decompress(src, dest); } } + public static final SrcDestTester BYTE_ARRAY = new ByteArrayTester(); public static final SrcDestTester BYTE_ARRAY_WITH_LENGTH = new ByteArrayTester() { @Override @@ -270,6 +273,7 @@ public int decompress(LZ4SafeDecompressor decompressor, ByteBuffer src, ByteBuff return dest.position() - pos; } } + public static final SrcDestTester BYTE_BUFFER = new ByteBufferTester(); public static final SrcDestTester BYTE_BUFFER_WITH_LENGTH = new ByteBufferTester() { @Override @@ -297,6 +301,7 @@ public int decompress(LZ4SafeDecompressor decompressor, ByteBuffer src, ByteBuff protected class RandomBytes { private final byte[] bytes; + RandomBytes(int n) { assert n > 0 && n <= 256; bytes = new byte[n]; @@ -304,6 +309,7 @@ protected class RandomBytes { bytes[i] = (byte) randomInt(255); } } + byte next() { final int i = randomInt(bytes.length - 1); return bytes[i]; diff --git a/src/test/net/jpountz/lz4/LZ4BlockStreamingTest.java b/src/test/net/jpountz/lz4/LZ4BlockStreamingTest.java index 9d5559c1..08845842 100644 --- a/src/test/net/jpountz/lz4/LZ4BlockStreamingTest.java +++ b/src/test/net/jpountz/lz4/LZ4BlockStreamingTest.java @@ -157,19 +157,19 @@ private OutputStream wrap(OutputStream other) { } @Test - @Repeat(iterations=5) + @Repeat(iterations = 5) public void testRoundtripGeo() throws IOException { testRoundTrip("/calgary/geo"); } @Test - @Repeat(iterations=5) + @Repeat(iterations = 5) public void testRoundtripBook1() throws IOException { testRoundTrip("/calgary/book1"); } @Test - @Repeat(iterations=5) + @Repeat(iterations = 5) public void testRoundtripPic() throws IOException { testRoundTrip("/calgary/pic"); } @@ -286,7 +286,7 @@ public void testRoundTrip(byte[] data) throws IOException { } @Test - @Repeat(iterations=20) + @Repeat(iterations = 20) public void testRoundtripRandom() throws IOException { final int size = randomFloat() < 0.1f ? randomInt(5) : randomInt(1 << 20); final byte[] data = randomArray(size, randomBoolean() ? randomIntBetween(1, 5) : randomIntBetween(6, 100)); @@ -327,7 +327,7 @@ private static int readFully(InputStream in, byte[] b) throws IOException { int result; for (total = 0; total < b.length; total += result) { result = in.read(b, total, b.length - total); - if(result == -1) { + if (result == -1) { break; } } diff --git a/src/test/net/jpountz/lz4/LZ4FrameIOStreamTest.java b/src/test/net/jpountz/lz4/LZ4FrameIOStreamTest.java index 221d00c0..22b582d1 100644 --- a/src/test/net/jpountz/lz4/LZ4FrameIOStreamTest.java +++ b/src/test/net/jpountz/lz4/LZ4FrameIOStreamTest.java @@ -54,7 +54,7 @@ public class LZ4FrameIOStreamTest { private static void copy(InputStream in, OutputStream out) throws IOException { final byte[] buffer = new byte[1 << 10]; - int inSize = in.read(buffer);; + int inSize = in.read(buffer); while (inSize >= 0) { out.write(buffer, 0, inSize); inSize = in.read(buffer); @@ -71,7 +71,7 @@ private static void copyWithPerByteReadWrite(InputStream in, OutputStream out) t } @Parameterized.Parameters - public static Iterable parameters(){ + public static Iterable parameters() { final List retval = new LinkedList<>( Arrays.asList( new Object[]{0}, @@ -83,7 +83,7 @@ public static Iterable parameters(){ new Object[]{1 << 20} )); final Random rnd = new Random(78370789134L); // Chosen by lightly smashing my keyboard a few times. - for(int i = 0; i < 10; ++i){ + for (int i = 0; i < 10; ++i) { retval.add(new Object[]{Math.abs(rnd.nextInt()) % (1 << 22)}); } return retval; @@ -91,7 +91,7 @@ public static Iterable parameters(){ private final int testSize; - public LZ4FrameIOStreamTest(int testSize){ + public LZ4FrameIOStreamTest(int testSize) { this.testSize = testSize; } @@ -120,7 +120,7 @@ public void setUp() throws IOException { @After public void tearDown() { - if (tmpFile != null && tmpFile.exists() && !tmpFile.delete()){ + if (tmpFile != null && tmpFile.exists() && !tmpFile.delete()) { Assert.fail(String.format("Could not delete file [%s]", tmpFile.getAbsolutePath())); } } @@ -155,15 +155,15 @@ private void validateStreamEquals(InputStream is, File file) throws IOException private void validateStreamEqualsWithPerByteRead(InputStream is, File file) throws IOException { try (InputStream fis = new FileInputStream(file)) { for (int size = (int) file.length(); size > 0; size--) { - int byte0 = is.read(); - int byte1 = fis.read(); - Assert.assertEquals(byte0, byte1); - if (byte0 == -1) { - throw new EOFException("End of stream"); - } - if (byte1 == -1) { - throw new EOFException("End of stream"); - } + int byte0 = is.read(); + int byte1 = fis.read(); + Assert.assertEquals(byte0, byte1); + if (byte0 == -1) { + throw new EOFException("End of stream"); + } + if (byte1 == -1) { + throw new EOFException("End of stream"); + } } } } @@ -292,7 +292,7 @@ public void testSkippableOnly() throws IOException { fos.write(skipBuffer.array()); } try (InputStream is = new LZ4FrameInputStream(new FileInputStream(lz4File))) { - Assert.assertEquals(-1, is.read()); + Assert.assertEquals(-1, is.read()); } // Extra one byte at the tail try (InputStream is = new LZ4FrameInputStream(new SequenceInputStream(new FileInputStream(lz4File), new ByteArrayInputStream(new byte[1])))) { @@ -385,7 +385,7 @@ public void testInputOutputMultipleFrames() throws IOException { } } final long oneLength = lz4File.length(); - try (OutputStream os = new FileOutputStream(lz4File, true)){ + try (OutputStream os = new FileOutputStream(lz4File, true)) { for (int i = 0; i < 3; ++i) { try (InputStream is = new FileInputStream(lz4File)) { long size = oneLength; @@ -449,7 +449,7 @@ private void nativeCompress(String... args) throws IOException, InterruptedExcep Process process = builder.start(); int retval = process.waitFor(); Assert.assertEquals(0, retval); - try(InputStream is = new LZ4FrameInputStream(new FileInputStream(lz4File))){ + try (InputStream is = new LZ4FrameInputStream(new FileInputStream(lz4File))) { validateStreamEquals(is, tmpFile); } } finally { @@ -459,22 +459,22 @@ private void nativeCompress(String... args) throws IOException, InterruptedExcep @Test public void testUncompressableEnd() throws IOException { - final byte data = (byte)0xEE; - try(final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { - try(final OutputStream os = new LZ4FrameOutputStream(baos, LZ4FrameOutputStream.BLOCKSIZE.SIZE_1MB)) { + final byte data = (byte) 0xEE; + try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + try (final OutputStream os = new LZ4FrameOutputStream(baos, LZ4FrameOutputStream.BLOCKSIZE.SIZE_1MB)) { os.write(data); } final byte[] bytes = baos.toByteArray(); - try(final InputStream is = new LZ4FrameInputStream(new ByteArrayInputStream(bytes))) { - Assert.assertEquals(data, (byte)is.read()); + try (final InputStream is = new LZ4FrameInputStream(new ByteArrayInputStream(bytes))) { + Assert.assertEquals(data, (byte) is.read()); } final ByteBuffer buffer = ByteBuffer.wrap(bytes); // Make sure final "block" is a zero length block, then set it to an incompressible zero length block. Assert.assertEquals(0, buffer.getInt(bytes.length - (Integer.SIZE >> 3))); buffer.putInt(bytes.length - (Integer.SIZE >> 3), LZ4FrameOutputStream.LZ4_FRAME_INCOMPRESSIBLE_MASK); - try(final InputStream is = new LZ4FrameInputStream(new ByteArrayInputStream(bytes))) { - Assert.assertEquals(data, (byte)is.read()); + try (final InputStream is = new LZ4FrameInputStream(new ByteArrayInputStream(bytes))) { + Assert.assertEquals(data, (byte) is.read()); } } } diff --git a/src/test/net/jpountz/lz4/LZ4Test.java b/src/test/net/jpountz/lz4/LZ4Test.java index de55807a..8f71d653 100644 --- a/src/test/net/jpountz/lz4/LZ4Test.java +++ b/src/test/net/jpountz/lz4/LZ4Test.java @@ -44,41 +44,43 @@ public void testLockFileOfTemporaryNativeLibrary() { String tempFolder = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath(); File tempDir = new File(new File(System.getProperty("java.io.tmpdir")).getAbsolutePath()); if (!System.getProperty("os.name").contains("Windows")) { - // A temporary library must be accompanied by a lock file. - // On Windows, JVM does not remove a temporary library on exit. - // This means on Windows, there might be a temporary library - // that is not accompanied by a lock file when there was - // a Java process using lz4-java that was running concurrently - // to this test process. - File[] tempLibFiles = tempDir.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.startsWith("liblz4-java-") && !name.endsWith(".lck"); - } - }); - if (tempLibFiles != null) { - for (File tempLibFile : tempLibFiles) { - File lckFile = new File(tempLibFile.getAbsolutePath() + ".lck"); - assertTrue(tempLibFile.getAbsolutePath(), lckFile.exists()); - } - } + // A temporary library must be accompanied by a lock file. + // On Windows, JVM does not remove a temporary library on exit. + // This means on Windows, there might be a temporary library + // that is not accompanied by a lock file when there was + // a Java process using lz4-java that was running concurrently + // to this test process. + File[] tempLibFiles = tempDir.listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.startsWith("liblz4-java-") && !name.endsWith(".lck"); + } + }); + if (tempLibFiles != null) { + for (File tempLibFile : tempLibFiles) { + File lckFile = new File(tempLibFile.getAbsolutePath() + ".lck"); + assertTrue(tempLibFile.getAbsolutePath(), lckFile.exists()); + } + } } // A lock file must be accompanied by a temporary library. File[] tempLockFiles = tempDir.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.startsWith("liblz4-java-") && name.endsWith(".lck"); - } - }); + @Override + public boolean accept(File dir, String name) { + return name.startsWith("liblz4-java-") && name.endsWith(".lck"); + } + }); if (tempLockFiles != null) { for (File tempLockFile : tempLockFiles) { - String tempLockFilePath = tempLockFile.getAbsolutePath(); - File libFile = new File(tempLockFilePath.substring(0, tempLockFilePath.length() - 4)); - assertTrue(tempLockFilePath, libFile.exists()); + String tempLockFilePath = tempLockFile.getAbsolutePath(); + File libFile = new File(tempLockFilePath.substring(0, tempLockFilePath.length() - 4)); + assertTrue(tempLockFilePath, libFile.exists()); } } } @Test - @Repeat(iterations=50) + @Repeat(iterations = 50) public void testMaxCompressedLength() { final int len = randomBoolean() ? randomInt(16) : randomInt(1 << 30); for (LZ4Compressor compressor : COMPRESSORS) { @@ -187,7 +189,7 @@ public void testRoundTrip( // make sure it fails if the compression dest is not large enough tester.fill(restored, randomByte()); - final T compressed2 = tester.allocate(compressedLen-1); + final T compressed2 = tester.allocate(compressedLen - 1); try { final int compressedLen2 = tester.compress(compressor, tester.copyOf(data), off, len, @@ -207,22 +209,22 @@ public void testRoundTrip( // because it ignores destLen. if (len > 0) { - // decompression dest is too small - try { - tester.decompress(decompressor, compressed, 0, restored, 0, len - 1); - fail(); - } catch (LZ4Exception e) { - // OK - } + // decompression dest is too small + try { + tester.decompress(decompressor, compressed, 0, restored, 0, len - 1); + fail(); + } catch (LZ4Exception e) { + // OK + } } // decompression dest is too large - final T restored2 = tester.allocate(len+1); + final T restored2 = tester.allocate(len + 1); try { - final int cpLen = tester.decompress(decompressor, compressed, 0, restored2, 0, len + 1); - fail("compressedLen=" + cpLen); + final int cpLen = tester.decompress(decompressor, compressed, 0, restored2, 0, len + 1); + fail("compressedLen=" + cpLen); } catch (LZ4Exception e) { - // OK + // OK } } @@ -267,23 +269,23 @@ public void testRoundTrip(SrcDestTester tester, original, compressed); if (original instanceof ByteBuffer) { - assertEquals(data.length, ((ByteBuffer)original).position()); - assertEquals(compressedLen, ((ByteBuffer)compressed).position()); - ((ByteBuffer)original).rewind(); - ((ByteBuffer)compressed).rewind(); + assertEquals(data.length, ((ByteBuffer) original).position()); + assertEquals(compressedLen, ((ByteBuffer) compressed).position()); + ((ByteBuffer) original).rewind(); + ((ByteBuffer) compressed).rewind(); } // test decompression final T restored = tester.allocate(data.length); assertEquals(compressedLen, tester.decompress(decompressor, compressed, restored)); if (original instanceof ByteBuffer) { - assertEquals(compressedLen, ((ByteBuffer)compressed).position()); - assertEquals(data.length, ((ByteBuffer)restored).position()); + assertEquals(compressedLen, ((ByteBuffer) compressed).position()); + assertEquals(data.length, ((ByteBuffer) restored).position()); } assertArrayEquals(data, tester.copyOf(restored, 0, data.length)); if (original instanceof ByteBuffer) { - ((ByteBuffer)compressed).rewind(); - ((ByteBuffer)restored).rewind(); + ((ByteBuffer) compressed).rewind(); + ((ByteBuffer) restored).rewind(); } // try decompression when only the size of the compressed buffer is known @@ -292,13 +294,13 @@ public void testRoundTrip(SrcDestTester tester, final T compressedExactSize = tester.copyOf(tester.copyOf(compressed, 0, compressedLen)); assertEquals(data.length, tester.decompress(decompressor2, compressedExactSize, restored)); if (original instanceof ByteBuffer) { - assertEquals(compressedLen, ((ByteBuffer)compressedExactSize).position()); - assertEquals(data.length, ((ByteBuffer)restored).position()); + assertEquals(compressedLen, ((ByteBuffer) compressedExactSize).position()); + assertEquals(data.length, ((ByteBuffer) restored).position()); } assertArrayEquals(data, tester.copyOf(restored, 0, data.length)); if (original instanceof ByteBuffer) { - ((ByteBuffer)compressedExactSize).rewind(); - ((ByteBuffer)restored).rewind(); + ((ByteBuffer) compressedExactSize).rewind(); + ((ByteBuffer) restored).rewind(); } } @@ -318,7 +320,7 @@ public void testRoundTrip(byte[] data, int off, int len) { LZ4Factory.nativeInsecureInstance(), LZ4Factory.unsafeInsecureInstance(), LZ4Factory.safeInstance())) { - testRoundTrip(data, off, len, compressorFactory, decompressorFactory); + testRoundTrip(data, off, len, compressorFactory, decompressorFactory); } } } @@ -454,7 +456,7 @@ public void testWriteToReadOnlyBuffer() { } @Test - @Repeat(iterations=5) + @Repeat(iterations = 5) public void testAllEqual() { final int len = randomBoolean() ? randomInt(20) : randomInt(100000); final byte[] buf = new byte[len]; @@ -475,7 +477,7 @@ public void testMaxDistance() { } @Test - @Repeat(iterations=10) + @Repeat(iterations = 10) public void testRandomData() { final int n = randomIntBetween(1, 15); final int off = randomInt(1000); @@ -596,7 +598,7 @@ public Sequence(int literalLen, int matchDec, int matchLen, int length) { @Override public String toString() { return "Sequence [literalLen=" + literalLen + ", matchDec=" + matchDec - + ", matchLen=" + matchLen + "]"; + + ", matchLen=" + matchLen + "]"; } @Override diff --git a/src/test/net/jpountz/xxhash/XXHash32Test.java b/src/test/net/jpountz/xxhash/XXHash32Test.java index 525f5d7d..c4aeed31 100644 --- a/src/test/net/jpountz/xxhash/XXHash32Test.java +++ b/src/test/net/jpountz/xxhash/XXHash32Test.java @@ -120,7 +120,7 @@ public void testAIOOBE() { } @Test - @Repeat(iterations=40) + @Repeat(iterations = 40) public void testInstances() { final int maxLenLog = randomInt(20); final int bufLen = randomInt(1 << maxLenLog); diff --git a/src/test/net/jpountz/xxhash/XXHash64Test.java b/src/test/net/jpountz/xxhash/XXHash64Test.java index 0ffd02e9..0dd3823b 100644 --- a/src/test/net/jpountz/xxhash/XXHash64Test.java +++ b/src/test/net/jpountz/xxhash/XXHash64Test.java @@ -122,7 +122,7 @@ public void testAIOOBE() { } @Test - @Repeat(iterations=40) + @Repeat(iterations = 40) public void testInstances() { final int maxLenLog = randomInt(20); final int bufLen = randomInt(1 << maxLenLog);