hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r988748 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/io/compress/BZip2Codec.java src/test/core/org/apache/hadoop/io/compress/TestCodec.java
Date Tue, 24 Aug 2010 22:40:05 GMT
Author: eli
Date: Tue Aug 24 22:40:05 2010
New Revision: 988748

URL: http://svn.apache.org/viewvc?rev=988748&view=rev
Log:
HADOOP-6925. BZip2Codec incorrectly implements read(). Contributed by Todd Lipcon.

Modified:
    hadoop/common/trunk/CHANGES.txt
    hadoop/common/trunk/src/java/org/apache/hadoop/io/compress/BZip2Codec.java
    hadoop/common/trunk/src/test/core/org/apache/hadoop/io/compress/TestCodec.java

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=988748&r1=988747&r2=988748&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Tue Aug 24 22:40:05 2010
@@ -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

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/io/compress/BZip2Codec.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/io/compress/BZip2Codec.java?rev=988748&r1=988747&r2=988748&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/io/compress/BZip2Codec.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/io/compress/BZip2Codec.java Tue Aug 24
22:40:05 2010
@@ -443,7 +443,7 @@ public class BZip2Codec implements Split
     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 {

Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/io/compress/TestCodec.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/io/compress/TestCodec.java?rev=988748&r1=988747&r2=988748&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/io/compress/TestCodec.java (original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/io/compress/TestCodec.java Tue Aug
24 22:40:05 2010
@@ -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");
   }
 



Mime
View raw message