This is an automated email from the ASF dual-hosted git repository.
sunchao pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push:
new 73a0c31 HADOOP-17877. BuiltInGzipCompressor header and trailer should
not be static variables (#3350)
73a0c31 is described below
commit 73a0c313705ac622bdc1ec465fc03b86ff347d9b
Author: Liang-Chi Hsieh <[email protected]>
AuthorDate: Sun Aug 29 08:21:55 2021 -0700
HADOOP-17877. BuiltInGzipCompressor header and trailer should not be static
variables (#3350)
---
.../io/compress/zlib/BuiltInGzipCompressor.java | 36 +++++++++++-----------
.../org/apache/hadoop/io/compress/TestCodec.java | 4 +--
2 files changed, 20 insertions(+), 20 deletions(-)
diff --git
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/zlib/BuiltInGzipCompressor.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/zlib/BuiltInGzipCompressor.java
index 3d676b5..61f7c12 100644
---
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/zlib/BuiltInGzipCompressor.java
+++
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/zlib/BuiltInGzipCompressor.java
@@ -39,15 +39,15 @@ public class BuiltInGzipCompressor implements Compressor {
* Fixed ten-byte gzip header. See {@link GZIPOutputStream}'s source for
* details.
*/
- private static final byte[] GZIP_HEADER = new byte[]{
+ private final byte[] gzipHeader = new byte[]{
0x1f, (byte) 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
// The trailer will be overwritten based on crc and output size.
- private static final byte[] GZIP_TRAILER = new byte[]{
+ private final byte[] gzipTrailer = new byte[]{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- private static final int GZIP_HEADER_LEN = GZIP_HEADER.length;
- private static final int GZIP_TRAILER_LEN = GZIP_TRAILER.length;
+ private final int gzipHeaderLen = gzipHeader.length;
+ private final int gzipTrailerLen = gzipTrailer.length;
private Deflater deflater;
@@ -210,12 +210,12 @@ public class BuiltInGzipCompressor implements Compressor {
return 0;
}
- int n = Math.min(len, GZIP_HEADER_LEN - headerOff);
- System.arraycopy(GZIP_HEADER, headerOff, b, off, n);
+ int n = Math.min(len, gzipHeaderLen - headerOff);
+ System.arraycopy(gzipHeader, headerOff, b, off, n);
headerOff += n;
// Completes header output.
- if (headerOff == GZIP_HEADER_LEN) {
+ if (headerOff == gzipHeaderLen) {
state = BuiltInGzipDecompressor.GzipStateLabel.INFLATE_STREAM;
}
@@ -225,15 +225,15 @@ public class BuiltInGzipCompressor implements Compressor {
private void fillTrailer() {
if (state == BuiltInGzipDecompressor.GzipStateLabel.TRAILER_CRC) {
int streamCrc = (int) crc.getValue();
- GZIP_TRAILER[0] = (byte) (streamCrc & 0x000000ff);
- GZIP_TRAILER[1] = (byte) ((streamCrc & 0x0000ff00) >> 8);
- GZIP_TRAILER[2] = (byte) ((streamCrc & 0x00ff0000) >> 16);
- GZIP_TRAILER[3] = (byte) ((streamCrc & 0xff000000) >> 24);
+ gzipTrailer[0] = (byte) (streamCrc & 0x000000ff);
+ gzipTrailer[1] = (byte) ((streamCrc & 0x0000ff00) >> 8);
+ gzipTrailer[2] = (byte) ((streamCrc & 0x00ff0000) >> 16);
+ gzipTrailer[3] = (byte) ((streamCrc & 0xff000000) >> 24);
- GZIP_TRAILER[4] = (byte) (accuBufLen & 0x000000ff);
- GZIP_TRAILER[5] = (byte) ((accuBufLen & 0x0000ff00) >> 8);
- GZIP_TRAILER[6] = (byte) ((accuBufLen & 0x00ff0000) >> 16);
- GZIP_TRAILER[7] = (byte) ((accuBufLen & 0xff000000) >> 24);
+ gzipTrailer[4] = (byte) (accuBufLen & 0x000000ff);
+ gzipTrailer[5] = (byte) ((accuBufLen & 0x0000ff00) >> 8);
+ gzipTrailer[6] = (byte) ((accuBufLen & 0x00ff0000) >> 16);
+ gzipTrailer[7] = (byte) ((accuBufLen & 0xff000000) >> 24);
crc.reset();
accuBufLen = 0;
@@ -245,11 +245,11 @@ public class BuiltInGzipCompressor implements Compressor {
return 0;
}
- int n = Math.min(len, GZIP_TRAILER_LEN - trailerOff);
- System.arraycopy(GZIP_TRAILER, trailerOff, b, off, n);
+ int n = Math.min(len, gzipTrailerLen - trailerOff);
+ System.arraycopy(gzipTrailer, trailerOff, b, off, n);
trailerOff += n;
- if (trailerOff == GZIP_TRAILER_LEN) {
+ if (trailerOff == gzipTrailerLen) {
state = BuiltInGzipDecompressor.GzipStateLabel.FINISHED;
currentBufLen = 0;
headerOff = 0;
diff --git
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/compress/TestCodec.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/compress/TestCodec.java
index 8f4e60e..e3afefd 100644
---
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/compress/TestCodec.java
+++
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/compress/TestCodec.java
@@ -109,7 +109,7 @@ public class TestCodec {
}
// without hadoop-native installed.
ZlibFactory.setNativeZlibLoaded(false);
- assumeTrue(ZlibFactory.isNativeZlibLoaded(conf));
+ assertFalse(ZlibFactory.isNativeZlibLoaded(conf));
codecTest(conf, seed, 0, "org.apache.hadoop.io.compress.GzipCodec");
codecTest(conf, seed, count, "org.apache.hadoop.io.compress.GzipCodec");
}
@@ -570,7 +570,7 @@ public class TestCodec {
}
// without hadoop-native installed.
ZlibFactory.setNativeZlibLoaded(false);
- assumeTrue(ZlibFactory.isNativeZlibLoaded(conf));
+ assertFalse(ZlibFactory.isNativeZlibLoaded(conf));
sequenceFileCodecTest(conf, 100,
"org.apache.hadoop.io.compress.GzipCodec", 5);
sequenceFileCodecTest(conf, 100,
"org.apache.hadoop.io.compress.GzipCodec", 100);
sequenceFileCodecTest(conf, 200000,
"org.apache.hadoop.io.compress.GzipCodec", 1000000);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]