Jelajahi Sumber

Merge -r 988747:988748 from trunk to branch-0.21. Fixes: HADOOP-6925.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.21@988750 13f79535-47bb-0310-9956-ffa450edef68
Eli Collins 14 tahun lalu
induk
melakukan
e090695b02

+ 7 - 0
CHANGES.txt

@@ -1,5 +1,12 @@
 Hadoop Change Log
 
+Release 0.21.1 - Unreleased
+
+  BUG FIXES
+
+    HADOOP-6925. BZip2Codec incorrectly implements read(). 
+    (Todd Lipcon via Eli Collins)
+
 Release 0.21.0 - 2010-08-13
 
   INCOMPATIBLE CHANGES

+ 1 - 1
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 {

+ 20 - 4
src/test/core/org/apache/hadoop/io/compress/TestCodec.java

@@ -129,10 +129,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
@@ -156,6 +152,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();
@@ -167,6 +166,23 @@ public class TestCodec {
       k2.readFields(inflateIn);
       v2.readFields(inflateIn);
     }
+
+    // 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");
   }