From 56a7fda830fe9c8a6f28a73e21631797036124a4 Mon Sep 17 00:00:00 2001 From: Eugene Kliuchnikov Date: Mon, 20 Feb 2017 14:04:55 +0100 Subject: Java: fix typos and adjust visibility. (#513) --- java/dec/BitReader.java | 8 ++++---- java/dec/BrotliInputStream.java | 6 +++--- java/dec/Decode.java | 18 +++++++++--------- java/dec/Dictionary.java | 10 +++++----- java/integration/BundleChecker.java | 13 +++++++------ 5 files changed, 28 insertions(+), 27 deletions(-) diff --git a/java/dec/BitReader.java b/java/dec/BitReader.java index b07d1b7..13ab9c4 100755 --- a/java/dec/BitReader.java +++ b/java/dec/BitReader.java @@ -47,7 +47,7 @@ class BitReader { int bitOffset; /** - * Number of 32-bit integers availabale for reading. + * Number of 32-bit integers available for reading. */ private int available; @@ -103,9 +103,9 @@ class BitReader { } /* When end of stream is reached, we "borrow" up to 64 zeroes to bit reader. * If compressed stream is valid, then borrowed zeroes should remain unused. */ - int valentBytes = (br.available << 2) + ((64 - br.bitOffset) >> 3); + int unusedBytes = (br.available << 2) + ((64 - br.bitOffset) >> 3); int borrowedBytes = 64 - br.tailBytes; - if (valentBytes != borrowedBytes) { + if (unusedBytes != borrowedBytes) { throw new BrotliRuntimeException("Read after end"); } } @@ -167,7 +167,7 @@ class BitReader { } } - static void jumpToByteBoundry(BitReader br) { + static void jumpToByteBoundary(BitReader br) { int padding = (64 - br.bitOffset) & 7; if (padding != 0) { int paddingBits = BitReader.readBits(br, padding); diff --git a/java/dec/BrotliInputStream.java b/java/dec/BrotliInputStream.java index 92ef15e..9117d9b 100755 --- a/java/dec/BrotliInputStream.java +++ b/java/dec/BrotliInputStream.java @@ -47,7 +47,7 @@ public class BrotliInputStream extends InputStream { *

Will block the thread until first kilobyte of data of source is available. * * @param source underlying data source - * @throws IOException in case of corrupred data or source stream problems + * @throws IOException in case of corrupted data or source stream problems */ public BrotliInputStream(InputStream source) throws IOException { this(source, DEFAULT_INTERNAL_BUFFER_SIZE, null); @@ -64,7 +64,7 @@ public class BrotliInputStream extends InputStream { * @param source compressed data source * @param byteReadBufferSize size of internal buffer used in case of * byte-by-byte reading - * @throws IOException in case of corrupred data or source stream problems + * @throws IOException in case of corrupted data or source stream problems */ public BrotliInputStream(InputStream source, int byteReadBufferSize) throws IOException { this(source, byteReadBufferSize, null); @@ -82,7 +82,7 @@ public class BrotliInputStream extends InputStream { * @param byteReadBufferSize size of internal buffer used in case of * byte-by-byte reading * @param customDictionary custom dictionary data; {@code null} if not used - * @throws IOException in case of corrupred data or source stream problems + * @throws IOException in case of corrupted data or source stream problems */ public BrotliInputStream(InputStream source, int byteReadBufferSize, byte[] customDictionary) throws IOException { diff --git a/java/dec/Decode.java b/java/dec/Decode.java index 39450c7..d7d3bf0 100755 --- a/java/dec/Decode.java +++ b/java/dec/Decode.java @@ -23,7 +23,7 @@ import static org.brotli.dec.RunningState.WRITE; /** * API for Brotli decompression. */ -public final class Decode { +final class Decode { private static final int DEFAULT_CODE_LENGTH = 8; private static final int CODE_LENGTH_REPEAT_CODE = 16; @@ -382,7 +382,7 @@ public final class Decode { state.distContextMapSlice = state.blockTypeRb[5] << DISTANCE_CONTEXT_BITS; } - static void maybeReallocateRingBuffer(State state) { + private static void maybeReallocateRingBuffer(State state) { int newSize = state.maxRingBufferSize; if ((long) newSize > state.expectedTotalSize) { /* TODO: Handle 2GB+ cases more gracefully. */ @@ -424,7 +424,7 @@ public final class Decode { * * @param state decoding state */ - static void readMeablockInfo(State state) { + private static void readMetablockInfo(State state) { final BitReader br = state.br; if (state.inputEnd) { @@ -448,7 +448,7 @@ public final class Decode { return; } if (state.isUncompressed || state.isMetadata) { - BitReader.jumpToByteBoundry(br); + BitReader.jumpToByteBoundary(br); state.runningState = state.isMetadata ? READ_METADATA : COPY_UNCOMPRESSED; } else { state.runningState = COMPRESSED_BLOCK_START; @@ -463,7 +463,7 @@ public final class Decode { } } - static void readMetablockHuffmanCodesAndContextMaps(State state) { + private static void readMetablockHuffmanCodesAndContextMaps(State state) { final BitReader br = state.br; for (int i = 0; i < 3; i++) { @@ -533,7 +533,7 @@ public final class Decode { state.blockTypeRb[1] = state.blockTypeRb[3] = state.blockTypeRb[5] = 0; } - static void copyUncompressedData(State state) { + private static void copyUncompressedData(State state) { final BitReader br = state.br; final byte[] ringBuffer = state.ringBuffer; final int ringBufferMask = state.ringBufferSize - 1; @@ -554,7 +554,7 @@ public final class Decode { state.runningState = BLOCK_START; } - static boolean writeRingBuffer(State state) { + private static boolean writeRingBuffer(State state) { /* Ignore custom dictionary bytes. */ if (state.bytesToIgnore != 0) { state.bytesWritten += state.bytesToIgnore; @@ -597,7 +597,7 @@ public final class Decode { if (state.metaBlockLength < 0) { throw new BrotliRuntimeException("Invalid metablock length"); } - readMeablockInfo(state); + readMetablockInfo(state); /* Ring-buffer would be reallocated here. */ ringBufferMask = state.ringBufferSize - 1; ringBuffer = state.ringBuffer; @@ -832,7 +832,7 @@ public final class Decode { if (state.metaBlockLength < 0) { throw new BrotliRuntimeException("Invalid metablock length"); } - BitReader.jumpToByteBoundry(br); + BitReader.jumpToByteBoundary(br); BitReader.checkHealth(state.br); } } diff --git a/java/dec/Dictionary.java b/java/dec/Dictionary.java index 4621867..a7f13ce 100755 --- a/java/dec/Dictionary.java +++ b/java/dec/Dictionary.java @@ -47,16 +47,16 @@ final class Dictionary { DATA = new byte[122784]; String[] chunks = {DataHolder0.getData(), DataHolder1.getData(), DataHolder2.getData()}; int sum = 0; - for (int i = 0; i < chunks.length; ++i) { - sum += chunks[i].length(); + for (String chunk : chunks) { + sum += chunk.length(); } if (sum != DATA.length) { throw new RuntimeException("Corrupted brotli dictionary"); } sum = 0; - for (int i = 0; i < chunks.length; ++i) { - for (int j = 0; j < chunks[i].length(); ++j) { - DATA[sum++] = (byte) chunks[i].charAt(j); + for (String chunk : chunks) { + for (int j = 0; j < chunk.length(); ++j) { + DATA[sum++] = (byte) chunk.charAt(j); } } } diff --git a/java/integration/BundleChecker.java b/java/integration/BundleChecker.java index 316f03c..435773f 100755 --- a/java/integration/BundleChecker.java +++ b/java/integration/BundleChecker.java @@ -26,9 +26,9 @@ import java.util.zip.ZipInputStream; * is expected to match the checksum hex-encoded in the first part of entry name. */ public class BundleChecker implements Runnable { - final AtomicInteger nextJob; - final InputStream input; - final boolean sanityCheck; + private final AtomicInteger nextJob; + private final InputStream input; + private final boolean sanityCheck; /** * @param sanityCheck do not calculate checksum and ignore {@link IOException}. @@ -40,7 +40,8 @@ public class BundleChecker implements Runnable { } /** ECMA CRC64 polynomial. */ - static final long CRC_64_POLY = new BigInteger("C96C5795D7870F42", 16).longValue(); + private static final long CRC_64_POLY = + new BigInteger("C96C5795D7870F42", 16).longValue(); /** * Rolls CRC64 calculation. @@ -78,7 +79,7 @@ public class BundleChecker implements Runnable { crc = updateCrc64(crc, buffer, 0, len); } decompressedStream.close(); - return crc ^ -1; + return ~crc; } @Override @@ -87,7 +88,7 @@ public class BundleChecker implements Runnable { ZipInputStream zis = new ZipInputStream(input); try { int entryIndex = 0; - ZipEntry entry = null; + ZipEntry entry; int jobIndex = nextJob.getAndIncrement(); while ((entry = zis.getNextEntry()) != null) { if (entry.isDirectory()) { -- cgit v1.1