Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/build/source_templates/xxhash64_streaming.template
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
44 changes: 22 additions & 22 deletions src/java-unsafe/net/jpountz/lz4/LZ4UnsafeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/java-unsafe/net/jpountz/util/UnsafeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/java/net/jpountz/lz4/LZ4BlockOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private void flushBufferedData() throws IOException {

/**
* Flushes this compressed {@link OutputStream}.
*
* <p>
* If the stream has been created with <code>syncFlush=true</code>, pending
* data will be compressed and appended to the underlying {@link OutputStream}
* before calling {@link OutputStream#flush()} on the underlying stream.
Expand Down
45 changes: 23 additions & 22 deletions src/java/net/jpountz/lz4/LZ4ByteBufferUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

enum LZ4ByteBufferUtils {
;

static int hash(ByteBuffer buf, int i) {
return LZ4Utils.hash(readInt(buf, i));
}
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/java/net/jpountz/lz4/LZ4Compressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final int maxCompressedLength(int length) {
* Compresses <code>src[srcOff:srcOff+srcLen]</code> into
* <code>dest[destOff:destOff+maxDestLen]</code> and returns the compressed
* length.
*
* <p>
* This method will throw a {@link LZ4Exception} if this compressor is unable
* to compress the input into less than <code>maxDestLen</code> bytes. To
* prevent this exception to be thrown, you should make sure that
Expand All @@ -62,12 +62,12 @@ public final int maxCompressedLength(int length) {
* Compresses <code>src[srcOff:srcOff+srcLen]</code> into
* <code>dest[destOff:destOff+maxDestLen]</code> and returns the compressed
* length.
*
* <p>
* This method will throw a {@link LZ4Exception} if this compressor is unable
* to compress the input into less than <code>maxDestLen</code> bytes. To
* prevent this exception to be thrown, you should make sure that
* <code>maxDestLen &gt;= maxCompressedLength(srcLen)</code>.
*
* <p>
* {@link ByteBuffer} positions remain unchanged.
*
* @param src the source data
Expand Down
22 changes: 11 additions & 11 deletions src/java/net/jpountz/lz4/LZ4CompressorWithLength.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -137,7 +137,7 @@ public int compress(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff
* Compresses <code>src[srcOff:srcOff+srcLen]</code> into
* <code>dest[destOff:destOff+maxDestLen]</code> and returns the compressed
* length.
*
* <p>
* This method will throw a {@link LZ4Exception} if this compressor is unable
* to compress the input into less than <code>maxDestLen</code> bytes. To
* prevent this exception to be thrown, you should make sure that
Expand Down Expand Up @@ -176,12 +176,12 @@ public void compress(ByteBuffer src, ByteBuffer dest) {
* Compresses <code>src[srcOff:srcOff+srcLen]</code> into
* <code>dest[destOff:destOff+maxDestLen]</code> and returns the compressed
* length.
*
* <p>
* This method will throw a {@link LZ4Exception} if this compressor is unable
* to compress the input into less than <code>maxDestLen</code> bytes. To
* prevent this exception to be thrown, you should make sure that
* <code>maxDestLen &gt;= maxCompressedLength(srcLen)</code>.
*
* <p>
* {@link ByteBuffer} positions remain unchanged.
*
* @param src the source data
Expand Down
4 changes: 2 additions & 2 deletions src/java/net/jpountz/lz4/LZ4Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/java/net/jpountz/lz4/LZ4DecompressorWithLength.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>src[srcOff:]</code> into <code>dest[destOff:]</code>
* and returns the number of bytes read from <code>src</code>, and
* when {@link LZ4SafeDecompressor} was specified to the constructor,
Expand Down
13 changes: 7 additions & 6 deletions src/java/net/jpountz/lz4/LZ4Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -231,22 +232,22 @@ private static <T> 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<? extends LZ4Compressor> 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);
}

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/java/net/jpountz/lz4/LZ4FastDecompressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
*/
public abstract class LZ4FastDecompressor implements LZ4Decompressor {

/** Decompresses <code>src[srcOff:]</code> into <code>dest[destOff:destOff+destLen]</code>
/**
* Decompresses <code>src[srcOff:]</code> into <code>dest[destOff:destOff+destLen]</code>
* and returns the number of bytes read from <code>src</code>.
* <code>destLen</code> must be exactly the size of the decompressed data.
*
Expand All @@ -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 <code>src[srcOff:]</code> into <code>dest[destOff:destOff+destLen]</code>
/**
* Decompresses <code>src[srcOff:]</code> into <code>dest[destOff:destOff+destLen]</code>
* and returns the number of bytes read from <code>src</code>.
* <code>destLen</code> must be exactly the size of the decompressed data.
* The positions and limits of the {@link ByteBuffer}s remain unchanged.
Expand Down
Loading