mirror of https://github.com/google/brotli
Java: fix typos and adjust visibility. (#513)
This commit is contained in:
parent
d03c38da7f
commit
56a7fda830
|
@ -47,7 +47,7 @@ class BitReader {
|
||||||
int bitOffset;
|
int bitOffset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of 32-bit integers availabale for reading.
|
* Number of 32-bit integers available for reading.
|
||||||
*/
|
*/
|
||||||
private int available;
|
private int available;
|
||||||
|
|
||||||
|
@ -103,9 +103,9 @@ class BitReader {
|
||||||
}
|
}
|
||||||
/* When end of stream is reached, we "borrow" up to 64 zeroes to bit reader.
|
/* 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. */
|
* 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;
|
int borrowedBytes = 64 - br.tailBytes;
|
||||||
if (valentBytes != borrowedBytes) {
|
if (unusedBytes != borrowedBytes) {
|
||||||
throw new BrotliRuntimeException("Read after end");
|
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;
|
int padding = (64 - br.bitOffset) & 7;
|
||||||
if (padding != 0) {
|
if (padding != 0) {
|
||||||
int paddingBits = BitReader.readBits(br, padding);
|
int paddingBits = BitReader.readBits(br, padding);
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class BrotliInputStream extends InputStream {
|
||||||
* <p> Will block the thread until first kilobyte of data of source is available.
|
* <p> Will block the thread until first kilobyte of data of source is available.
|
||||||
*
|
*
|
||||||
* @param source underlying data source
|
* @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 {
|
public BrotliInputStream(InputStream source) throws IOException {
|
||||||
this(source, DEFAULT_INTERNAL_BUFFER_SIZE, null);
|
this(source, DEFAULT_INTERNAL_BUFFER_SIZE, null);
|
||||||
|
@ -64,7 +64,7 @@ public class BrotliInputStream extends InputStream {
|
||||||
* @param source compressed data source
|
* @param source compressed data source
|
||||||
* @param byteReadBufferSize size of internal buffer used in case of
|
* @param byteReadBufferSize size of internal buffer used in case of
|
||||||
* byte-by-byte reading
|
* 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 {
|
public BrotliInputStream(InputStream source, int byteReadBufferSize) throws IOException {
|
||||||
this(source, byteReadBufferSize, null);
|
this(source, byteReadBufferSize, null);
|
||||||
|
@ -82,7 +82,7 @@ public class BrotliInputStream extends InputStream {
|
||||||
* @param byteReadBufferSize size of internal buffer used in case of
|
* @param byteReadBufferSize size of internal buffer used in case of
|
||||||
* byte-by-byte reading
|
* byte-by-byte reading
|
||||||
* @param customDictionary custom dictionary data; {@code null} if not used
|
* @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,
|
public BrotliInputStream(InputStream source, int byteReadBufferSize,
|
||||||
byte[] customDictionary) throws IOException {
|
byte[] customDictionary) throws IOException {
|
||||||
|
|
|
@ -23,7 +23,7 @@ import static org.brotli.dec.RunningState.WRITE;
|
||||||
/**
|
/**
|
||||||
* API for Brotli decompression.
|
* API for Brotli decompression.
|
||||||
*/
|
*/
|
||||||
public final class Decode {
|
final class Decode {
|
||||||
|
|
||||||
private static final int DEFAULT_CODE_LENGTH = 8;
|
private static final int DEFAULT_CODE_LENGTH = 8;
|
||||||
private static final int CODE_LENGTH_REPEAT_CODE = 16;
|
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;
|
state.distContextMapSlice = state.blockTypeRb[5] << DISTANCE_CONTEXT_BITS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void maybeReallocateRingBuffer(State state) {
|
private static void maybeReallocateRingBuffer(State state) {
|
||||||
int newSize = state.maxRingBufferSize;
|
int newSize = state.maxRingBufferSize;
|
||||||
if ((long) newSize > state.expectedTotalSize) {
|
if ((long) newSize > state.expectedTotalSize) {
|
||||||
/* TODO: Handle 2GB+ cases more gracefully. */
|
/* TODO: Handle 2GB+ cases more gracefully. */
|
||||||
|
@ -424,7 +424,7 @@ public final class Decode {
|
||||||
*
|
*
|
||||||
* @param state decoding state
|
* @param state decoding state
|
||||||
*/
|
*/
|
||||||
static void readMeablockInfo(State state) {
|
private static void readMetablockInfo(State state) {
|
||||||
final BitReader br = state.br;
|
final BitReader br = state.br;
|
||||||
|
|
||||||
if (state.inputEnd) {
|
if (state.inputEnd) {
|
||||||
|
@ -448,7 +448,7 @@ public final class Decode {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (state.isUncompressed || state.isMetadata) {
|
if (state.isUncompressed || state.isMetadata) {
|
||||||
BitReader.jumpToByteBoundry(br);
|
BitReader.jumpToByteBoundary(br);
|
||||||
state.runningState = state.isMetadata ? READ_METADATA : COPY_UNCOMPRESSED;
|
state.runningState = state.isMetadata ? READ_METADATA : COPY_UNCOMPRESSED;
|
||||||
} else {
|
} else {
|
||||||
state.runningState = COMPRESSED_BLOCK_START;
|
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;
|
final BitReader br = state.br;
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
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;
|
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 BitReader br = state.br;
|
||||||
final byte[] ringBuffer = state.ringBuffer;
|
final byte[] ringBuffer = state.ringBuffer;
|
||||||
final int ringBufferMask = state.ringBufferSize - 1;
|
final int ringBufferMask = state.ringBufferSize - 1;
|
||||||
|
@ -554,7 +554,7 @@ public final class Decode {
|
||||||
state.runningState = BLOCK_START;
|
state.runningState = BLOCK_START;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean writeRingBuffer(State state) {
|
private static boolean writeRingBuffer(State state) {
|
||||||
/* Ignore custom dictionary bytes. */
|
/* Ignore custom dictionary bytes. */
|
||||||
if (state.bytesToIgnore != 0) {
|
if (state.bytesToIgnore != 0) {
|
||||||
state.bytesWritten += state.bytesToIgnore;
|
state.bytesWritten += state.bytesToIgnore;
|
||||||
|
@ -597,7 +597,7 @@ public final class Decode {
|
||||||
if (state.metaBlockLength < 0) {
|
if (state.metaBlockLength < 0) {
|
||||||
throw new BrotliRuntimeException("Invalid metablock length");
|
throw new BrotliRuntimeException("Invalid metablock length");
|
||||||
}
|
}
|
||||||
readMeablockInfo(state);
|
readMetablockInfo(state);
|
||||||
/* Ring-buffer would be reallocated here. */
|
/* Ring-buffer would be reallocated here. */
|
||||||
ringBufferMask = state.ringBufferSize - 1;
|
ringBufferMask = state.ringBufferSize - 1;
|
||||||
ringBuffer = state.ringBuffer;
|
ringBuffer = state.ringBuffer;
|
||||||
|
@ -832,7 +832,7 @@ public final class Decode {
|
||||||
if (state.metaBlockLength < 0) {
|
if (state.metaBlockLength < 0) {
|
||||||
throw new BrotliRuntimeException("Invalid metablock length");
|
throw new BrotliRuntimeException("Invalid metablock length");
|
||||||
}
|
}
|
||||||
BitReader.jumpToByteBoundry(br);
|
BitReader.jumpToByteBoundary(br);
|
||||||
BitReader.checkHealth(state.br);
|
BitReader.checkHealth(state.br);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,16 +47,16 @@ final class Dictionary {
|
||||||
DATA = new byte[122784];
|
DATA = new byte[122784];
|
||||||
String[] chunks = {DataHolder0.getData(), DataHolder1.getData(), DataHolder2.getData()};
|
String[] chunks = {DataHolder0.getData(), DataHolder1.getData(), DataHolder2.getData()};
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
for (int i = 0; i < chunks.length; ++i) {
|
for (String chunk : chunks) {
|
||||||
sum += chunks[i].length();
|
sum += chunk.length();
|
||||||
}
|
}
|
||||||
if (sum != DATA.length) {
|
if (sum != DATA.length) {
|
||||||
throw new RuntimeException("Corrupted brotli dictionary");
|
throw new RuntimeException("Corrupted brotli dictionary");
|
||||||
}
|
}
|
||||||
sum = 0;
|
sum = 0;
|
||||||
for (int i = 0; i < chunks.length; ++i) {
|
for (String chunk : chunks) {
|
||||||
for (int j = 0; j < chunks[i].length(); ++j) {
|
for (int j = 0; j < chunk.length(); ++j) {
|
||||||
DATA[sum++] = (byte) chunks[i].charAt(j);
|
DATA[sum++] = (byte) chunk.charAt(j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,9 @@ import java.util.zip.ZipInputStream;
|
||||||
* is expected to match the checksum hex-encoded in the first part of entry name.
|
* is expected to match the checksum hex-encoded in the first part of entry name.
|
||||||
*/
|
*/
|
||||||
public class BundleChecker implements Runnable {
|
public class BundleChecker implements Runnable {
|
||||||
final AtomicInteger nextJob;
|
private final AtomicInteger nextJob;
|
||||||
final InputStream input;
|
private final InputStream input;
|
||||||
final boolean sanityCheck;
|
private final boolean sanityCheck;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param sanityCheck do not calculate checksum and ignore {@link IOException}.
|
* @param sanityCheck do not calculate checksum and ignore {@link IOException}.
|
||||||
|
@ -40,7 +40,8 @@ public class BundleChecker implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ECMA CRC64 polynomial. */
|
/** 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.
|
* Rolls CRC64 calculation.
|
||||||
|
@ -78,7 +79,7 @@ public class BundleChecker implements Runnable {
|
||||||
crc = updateCrc64(crc, buffer, 0, len);
|
crc = updateCrc64(crc, buffer, 0, len);
|
||||||
}
|
}
|
||||||
decompressedStream.close();
|
decompressedStream.close();
|
||||||
return crc ^ -1;
|
return ~crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -87,7 +88,7 @@ public class BundleChecker implements Runnable {
|
||||||
ZipInputStream zis = new ZipInputStream(input);
|
ZipInputStream zis = new ZipInputStream(input);
|
||||||
try {
|
try {
|
||||||
int entryIndex = 0;
|
int entryIndex = 0;
|
||||||
ZipEntry entry = null;
|
ZipEntry entry;
|
||||||
int jobIndex = nextJob.getAndIncrement();
|
int jobIndex = nextJob.getAndIncrement();
|
||||||
while ((entry = zis.getNextEntry()) != null) {
|
while ((entry = zis.getNextEntry()) != null) {
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
|
|
Loading…
Reference in New Issue