Skip to content

Commit

Permalink
Fix IntelliJ warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed Mar 20, 2024
1 parent 8bd2636 commit 4538c66
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 53 deletions.
3 changes: 2 additions & 1 deletion src/main/java/io/airlift/compress/snappy/Crc32C.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* and implemented on many Intel chipsets supporting SSE4.2.
*/
// this code was taken from Apache Hadoop
class Crc32C
final class Crc32C
implements Checksum
{
private static final int MASK_DELTA = 0xa282ead8;
Expand Down Expand Up @@ -126,6 +126,7 @@ public void update(byte[] b, int off, int len)
crc = localCrc;
}

@Override
public void update(int b)
{
crc = (crc >>> 8) ^ T8_0[(crc ^ b) & 0xff];
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/airlift/compress/zstd/BitInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* <p>
* ... [16 17 18 19 20 21 22 23] [8 9 10 11 12 13 14 15] [0 1 2 3 4 5 6 7]
*/
class BitInputStream
final class BitInputStream
{
private BitInputStream()
{
Expand All @@ -36,7 +36,7 @@ public static boolean isEndOfStream(long startAddress, long currentAddress, int
return startAddress == currentAddress && bitsConsumed == Long.SIZE;
}

static long readTail(Object inputBase, long inputAddress, int inputSize)
private static long readTail(Object inputBase, long inputAddress, int inputSize)
{
long bits = UNSAFE.getByte(inputBase, inputAddress) & 0xFF;

Expand All @@ -59,7 +59,7 @@ static long readTail(Object inputBase, long inputAddress, int inputSize)
}

/**
* @return numberOfBits in the low order bits of a long
* @return numberOfBits in the low-order bits of a long
*/
public static long peekBits(int bitsConsumed, long bitContainer, int numberOfBits)
{
Expand All @@ -69,7 +69,7 @@ public static long peekBits(int bitsConsumed, long bitContainer, int numberOfBit
/**
* numberOfBits must be > 0
*
* @return numberOfBits in the low order bits of a long
* @return numberOfBits in the low-order bits of a long
*/
public static long peekBitsFast(int bitsConsumed, long bitContainer, int numberOfBits)
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/airlift/compress/zstd/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package io.airlift.compress.zstd;

class Constants
final class Constants
{
public static final int SIZE_OF_BYTE = 1;
public static final int SIZE_OF_SHORT = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class DoubleFastBlockCompressor
private static final int SEARCH_STRENGTH = 8;
private static final int REP_MOVE = Constants.REPEATED_OFFSET_COUNT - 1;

@Override
public int compressBlock(Object inputBase, final long inputAddress, int inputSize, SequenceStore output, BlockCompressionState state, RepeatedOffsets offsets, CompressionParameters parameters)
{
int matchSearchLength = Math.max(parameters.getSearchLength(), 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static io.airlift.compress.zstd.Util.verify;
import static sun.misc.Unsafe.ARRAY_BYTE_BASE_OFFSET;

class FiniteStateEntropy
final class FiniteStateEntropy
{
public static final int MAX_SYMBOL = 255;
public static final int MAX_TABLE_LOG = 12;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/airlift/compress/zstd/Histogram.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import static io.airlift.compress.zstd.UnsafeUtil.UNSAFE;
import static sun.misc.Unsafe.ARRAY_BYTE_BASE_OFFSET;

class Histogram
final class Histogram
{
private Histogram()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static io.airlift.compress.zstd.Constants.SIZE_OF_SHORT;
import static io.airlift.compress.zstd.UnsafeUtil.UNSAFE;

class HuffmanCompressor
final class HuffmanCompressor
{
private HuffmanCompressor()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static io.airlift.compress.zstd.UnsafeUtil.UNSAFE;
import static io.airlift.compress.zstd.Util.checkArgument;

class SequenceEncoder
final class SequenceEncoder
{
private static final int DEFAULT_LITERAL_LENGTH_NORMALIZED_COUNTS_LOG = 6;
private static final short[] DEFAULT_LITERAL_LENGTH_NORMALIZED_COUNTS = {4, 3, 2, 2, 2, 2, 2, 2,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/airlift/compress/zstd/SequenceStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static io.airlift.compress.zstd.UnsafeUtil.UNSAFE;
import static sun.misc.Unsafe.ARRAY_BYTE_BASE_OFFSET;

class SequenceStore
final class SequenceStore
{
public final byte[] literalsBuffer;
public int literalsLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import static io.airlift.compress.zstd.Util.put24BitLittleEndian;
import static sun.misc.Unsafe.ARRAY_BYTE_BASE_OFFSET;

class ZstdFrameCompressor
final class ZstdFrameCompressor
{
static final int MAX_FRAME_HEADER_SIZE = 14;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,13 @@ private void verifyCompressByteBuffer(Compressor compressor, ByteBuffer expected
if (expected.remaining() > 1) {
ByteBuffer duplicate = expected.duplicate();
duplicate.get(); // skip one byte
compressor.compress(duplicate, ByteBuffer.allocate(((Buffer) compressed).remaining()));
compressor.compress(duplicate, ByteBuffer.allocate(compressed.remaining()));
}

compressor.compress(expected.duplicate(), compressed);
((Buffer) compressed).flip();

ByteBuffer uncompressed = ByteBuffer.allocate(((Buffer) expected).remaining());
ByteBuffer uncompressed = ByteBuffer.allocate(expected.remaining());

// TODO: validate with "control" decompressor
getDecompressor().decompress(compressed, uncompressed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class MockJdkDeflateCompressor
{
private static final int OVERHEAD = 128;

@Override
public int maxCompressedLength(int uncompressedSize)
{
return uncompressedSize + OVERHEAD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class MockJdkGzipCompressor
{
private static final int OVERHEAD = 128;

@Override
public int maxCompressedLength(int uncompressedSize)
{
return uncompressedSize + OVERHEAD;
Expand Down
30 changes: 6 additions & 24 deletions src/test/java/io/airlift/compress/snappy/TestSnappyStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -116,7 +115,7 @@ void testEmptyCompression()
@Test
void testShortBlockHeader()
{
assertThatThrownBy(() -> uncompressBlock(new byte[] {0}))
assertThatThrownBy(() -> uncompress(blockToStream(new byte[] {0})))
.isInstanceOf(EOFException.class)
.hasMessageContaining("block header");
}
Expand All @@ -125,7 +124,7 @@ void testShortBlockHeader()
void testShortBlockData()
{
// flag = 0, size = 8, crc32c = 0, block data= [x, x]
assertThatThrownBy(() -> uncompressBlock(new byte[] {1, 8, 0, 0, 0, 0, 0, 0, 'x', 'x'}))
assertThatThrownBy(() -> uncompress(blockToStream(new byte[] {1, 8, 0, 0, 0, 0, 0, 0, 'x', 'x'})))
.isInstanceOf(EOFException.class)
.hasMessageContaining("reading frame");
}
Expand All @@ -135,7 +134,7 @@ void testUnskippableChunkFlags()
{
for (int i = 2; i <= 0x7f; i++) {
int value = i;
assertThatThrownBy(() -> uncompressBlock(new byte[] {(byte) value, 5, 0, 0, 0, 0, 0, 0, 0}))
assertThatThrownBy(() -> uncompress(blockToStream(new byte[] {(byte) value, 5, 0, 0, 0, 0, 0, 0, 0})))
.isInstanceOf(IOException.class);
}
}
Expand All @@ -145,7 +144,7 @@ void testSkippableChunkFlags()
{
for (int i = 0x80; i <= 0xfe; i++) {
try {
uncompressBlock(new byte[] {(byte) i, 5, 0, 0, 0, 0, 0, 0, 0});
uncompress(blockToStream(new byte[] {(byte) i, 5, 0, 0, 0, 0, 0, 0, 0}));
}
catch (IOException e) {
throw new AssertionError("exception thrown with flag: " + Integer.toHexString(i), e);
Expand All @@ -157,7 +156,7 @@ void testSkippableChunkFlags()
void testInvalidBlockSizeZero()
{
// flag = '0', block size = 4, crc32c = 0
assertThatThrownBy(() -> uncompressBlock(new byte[] {1, 4, 0, 0, 0, 0, 0, 0}))
assertThatThrownBy(() -> uncompress(blockToStream(new byte[] {1, 4, 0, 0, 0, 0, 0, 0})))
.isInstanceOf(IOException.class)
.hasMessageMatching(".*invalid length.*4.*");
}
Expand All @@ -166,7 +165,7 @@ void testInvalidBlockSizeZero()
void testInvalidChecksum()
{
// flag = 0, size = 5, crc32c = 0, block data = [a]
assertThatThrownBy(() -> uncompressBlock(new byte[] {1, 5, 0, 0, 0, 0, 0, 0, 'a'}))
assertThatThrownBy(() -> uncompress(blockToStream(new byte[] {1, 5, 0, 0, 0, 0, 0, 0, 'a'})))
.isInstanceOf(IOException.class)
.hasMessage("Corrupt input: invalid checksum");
}
Expand Down Expand Up @@ -272,12 +271,6 @@ void testLargerFrames_compressed_smaller_raw_larger()
assertThat(random).isEqualTo(uncompressed);
}

private static byte[] uncompressBlock(byte[] block)
throws IOException
{
return uncompress(blockToStream(block));
}

private static byte[] blockToStream(byte[] block)
{
byte[] stream = new byte[SnappyFramed.HEADER_BYTES.length + block.length];
Expand Down Expand Up @@ -499,15 +492,4 @@ private static byte[] uncompress(byte[] compressed)
{
return toByteArray(new SnappyFramedInputStream(new ByteArrayInputStream(compressed)));
}

private static File[] getTestFiles()
{
File[] testFiles = TEST_DATA_DIR.listFiles();
assertThat(testFiles != null && testFiles.length > 0)
.withFailMessage("No test files at " + TEST_DATA_DIR.getAbsolutePath())
.isTrue();
return testFiles;
}

private static final File TEST_DATA_DIR = new File("testdata");
}
21 changes: 10 additions & 11 deletions src/test/java/io/airlift/compress/zstd/TestZstd.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ void testDecompressWithOutputPaddingAndChecksum()
{
int padding = 1021;

byte[] compressed = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/with-checksum.zst"));
byte[] uncompressed = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/with-checksum"));
byte[] compressed = Resources.toByteArray(Resources.getResource(getClass(), "data/zstd/with-checksum.zst"));
byte[] uncompressed = Resources.toByteArray(Resources.getResource(getClass(), "data/zstd/with-checksum"));

byte[] output = new byte[uncompressed.length + padding * 2]; // pre + post padding
int decompressedSize = getDecompressor().decompress(compressed, 0, compressed.length, output, padding, output.length - padding);
Expand All @@ -80,8 +80,8 @@ void testDecompressWithOutputPaddingAndChecksum()
void testConcatenatedFrames()
throws IOException
{
byte[] compressed = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/multiple-frames.zst"));
byte[] uncompressed = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/multiple-frames"));
byte[] compressed = Resources.toByteArray(Resources.getResource(getClass(), "data/zstd/multiple-frames.zst"));
byte[] uncompressed = Resources.toByteArray(Resources.getResource(getClass(), "data/zstd/multiple-frames"));

byte[] output = new byte[uncompressed.length];
getDecompressor().decompress(compressed, 0, compressed.length, output, 0, output.length);
Expand All @@ -93,7 +93,7 @@ void testConcatenatedFrames()
void testInvalidSequenceOffset()
throws IOException
{
byte[] compressed = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/offset-before-start.zst"));
byte[] compressed = Resources.toByteArray(Resources.getResource(getClass(), "data/zstd/offset-before-start.zst"));
byte[] output = new byte[compressed.length * 10];

assertThatThrownBy(() -> getDecompressor().decompress(compressed, 0, compressed.length, output, 0, output.length))
Expand All @@ -109,7 +109,7 @@ void testSmallLiteralsAfterIncompressibleLiterals()
// which ended up emitting raw literals due to insufficient gain
Compressor compressor = getCompressor();

byte[] original = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/small-literals-after-incompressible-literals"));
byte[] original = Resources.toByteArray(Resources.getResource(getClass(), "data/zstd/small-literals-after-incompressible-literals"));
int maxCompressLength = compressor.maxCompressedLength(original.length);

byte[] compressed = new byte[maxCompressLength];
Expand All @@ -129,7 +129,7 @@ void testLargeRle()

Compressor compressor = getCompressor();

byte[] original = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/large-rle"));
byte[] original = Resources.toByteArray(Resources.getResource(getClass(), "data/zstd/large-rle"));
int maxCompressLength = compressor.maxCompressedLength(original.length);

byte[] compressed = new byte[maxCompressLength];
Expand All @@ -149,7 +149,7 @@ void testIncompressibleData()

Compressor compressor = getCompressor();

byte[] original = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/incompressible"));
byte[] original = Resources.toByteArray(Resources.getResource(getClass(), "data/zstd/incompressible"));
int maxCompressLength = compressor.maxCompressedLength(original.length);

byte[] compressed = new byte[maxCompressLength];
Expand Down Expand Up @@ -200,9 +200,8 @@ private void testGetDecompressedSize(DataSet dataSet)
void testVerifyMagicInAllFrames()
throws IOException
{
Compressor compressor = getCompressor();
byte[] compressed = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/bad-second-frame.zst"));
byte[] uncompressed = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/multiple-frames"));
byte[] compressed = Resources.toByteArray(Resources.getResource(getClass(), "data/zstd/bad-second-frame.zst"));
byte[] uncompressed = Resources.toByteArray(Resources.getResource(getClass(), "data/zstd/multiple-frames"));
byte[] output = new byte[uncompressed.length];
assertThatThrownBy(() -> getDecompressor().decompress(compressed, 0, compressed.length, output, 0, output.length))
.isInstanceOf(MalformedInputException.class)
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/airlift/compress/zstd/TestZstdCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ protected Decompressor getVerifyDecompressor()
void testConcatenatedFrames()
throws IOException
{
byte[] compressed = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/multiple-frames.zst"));
byte[] uncompressed = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/multiple-frames"));
byte[] compressed = Resources.toByteArray(Resources.getResource(getClass(), "data/zstd/multiple-frames.zst"));
byte[] uncompressed = Resources.toByteArray(Resources.getResource(getClass(), "data/zstd/multiple-frames"));

byte[] output = new byte[uncompressed.length];
getVerifyDecompressor().decompress(compressed, 0, compressed.length, output, 0, output.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ protected Decompressor getVerifyDecompressor()
void testConcatenatedFrames()
throws IOException
{
byte[] compressed = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/multiple-frames.zst"));
byte[] uncompressed = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/multiple-frames"));
byte[] compressed = Resources.toByteArray(Resources.getResource(getClass(), "data/zstd/multiple-frames.zst"));
byte[] uncompressed = Resources.toByteArray(Resources.getResource(getClass(), "data/zstd/multiple-frames"));

byte[] output = new byte[uncompressed.length];
getVerifyDecompressor().decompress(compressed, 0, compressed.length, output, 0, output.length);
Expand Down

0 comments on commit 4538c66

Please sign in to comment.