diff --git a/CHANGES.txt b/CHANGES.txt index 8c06c23aed6..f2114f85fdb 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -211,6 +211,9 @@ Trunk (unreleased changes) HADOOP-6453. Hadoop wrapper script shouldn't ignore an existing JAVA_LIBRARY_PATH. (Chad Metcalf via jghoman) + HADOOP-6925. BZip2Codec incorrectly implements read(). + (Todd Lipcon via Eli Collins) + Release 0.21.0 - Unreleased INCOMPATIBLE CHANGES diff --git a/src/java/org/apache/hadoop/io/compress/BZip2Codec.java b/src/java/org/apache/hadoop/io/compress/BZip2Codec.java index 0de73e9856c..a7a925f35a1 100644 --- a/src/java/org/apache/hadoop/io/compress/BZip2Codec.java +++ b/src/java/org/apache/hadoop/io/compress/BZip2Codec.java @@ -443,7 +443,7 @@ public class BZip2Codec implements SplittableCompressionCodec { public int read() throws IOException { byte b[] = new byte[1]; int result = this.read(b, 0, 1); - return (result < 0) ? result : b[0]; + return (result < 0) ? result : (b[0] & 0xff); } private void internalReset() throws IOException { diff --git a/src/test/core/org/apache/hadoop/io/compress/TestCodec.java b/src/test/core/org/apache/hadoop/io/compress/TestCodec.java index 9b2435a0a19..26981d312f1 100644 --- a/src/test/core/org/apache/hadoop/io/compress/TestCodec.java +++ b/src/test/core/org/apache/hadoop/io/compress/TestCodec.java @@ -131,10 +131,6 @@ public class TestCodec { key.write(data); value.write(data); } - DataInputBuffer originalData = new DataInputBuffer(); - DataInputStream originalIn = new DataInputStream(new BufferedInputStream(originalData)); - originalData.reset(data.getData(), 0, data.getLength()); - LOG.info("Generated " + count + " records"); // Compress data @@ -158,6 +154,9 @@ public class TestCodec { new DataInputStream(new BufferedInputStream(inflateFilter)); // Check + DataInputBuffer originalData = new DataInputBuffer(); + originalData.reset(data.getData(), 0, data.getLength()); + DataInputStream originalIn = new DataInputStream(new BufferedInputStream(originalData)); for(int i=0; i < count; ++i) { RandomDatum k1 = new RandomDatum(); RandomDatum v1 = new RandomDatum(); @@ -171,6 +170,23 @@ public class TestCodec { assertTrue("original and compressed-then-decompressed-output not equal", k1.equals(k2) && v1.equals(v2)); } + + // De-compress data byte-at-a-time + originalData.reset(data.getData(), 0, data.getLength()); + deCompressedDataBuffer.reset(compressedDataBuffer.getData(), 0, + compressedDataBuffer.getLength()); + inflateFilter = + codec.createInputStream(deCompressedDataBuffer); + + // Check + originalIn = new DataInputStream(new BufferedInputStream(originalData)); + int expected; + do { + expected = originalIn.read(); + assertEquals("Inflated stream read by byte does not match", + expected, inflateFilter.read()); + } while (expected != -1); + LOG.info("SUCCESS! Completed checking " + count + " records"); }