소스 검색

HADOOP-3569. KFS input stream read() now correctly reads 1 byte
instead of 4. Contributed by Sriram Rao.


git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@669639 13f79535-47bb-0310-9956-ffa450edef68

Owen O'Malley 17 년 전
부모
커밋
48c3c8d51a
3개의 변경된 파일17개의 추가작업 그리고 5개의 파일을 삭제
  1. 3 0
      CHANGES.txt
  2. 4 4
      src/core/org/apache/hadoop/fs/kfs/KFSInputStream.java
  3. 10 1
      src/test/org/apache/hadoop/fs/kfs/TestKosmosFileSystem.java

+ 3 - 0
CHANGES.txt

@@ -631,6 +631,9 @@ Release 0.18.0 - Unreleased
     HADOOP-3546. TaskTracker re-initialization gets stuck in cleaning up.
     (Amareshwari Sriramadasu via ddas)
 
+    HADOOP-3569. KFS input stream read() now correctly reads 1 byte
+    instead of 4. (Sriram Rao via omalley)
+
 Release 0.17.1 - Unreleased
 
   INCOMPATIBLE CHANGES

+ 4 - 4
src/core/org/apache/hadoop/fs/kfs/KFSInputStream.java

@@ -79,13 +79,13 @@ class KFSInputStream extends FSInputStream {
         if (kfsChannel == null) {
             throw new IOException("File closed");
         }
-        byte b[] = new byte[4];
-        int res = read(b, 0, 4);
-        if (res == 4) {
+        byte b[] = new byte[1];
+        int res = read(b, 0, 1);
+        if (res == 1) {
           if (statistics != null) {
             statistics.incrementBytesRead(1);
           }
-          return (b[0] + (b[1] << 8) + (b[2] << 16) + (b[3] << 24));          
+          return ((int) (b[0] & 0xff));
         }
         return -1;
     }

+ 10 - 1
src/test/org/apache/hadoop/fs/kfs/TestKosmosFileSystem.java

@@ -134,7 +134,10 @@ public class TestKosmosFileSystem extends TestCase {
         for (int i = 0; i < data.length; i++)
             data[i] = (byte) (i % 16);
 
-        // write an integer
+        // write 4 bytes and read them back; read API should return a byte per call
+        s1.write(32);
+        s1.write(32);
+        s1.write(32);
         s1.write(32);
         // write some data
         s1.write(data, 0, data.length);
@@ -145,6 +148,12 @@ public class TestKosmosFileSystem extends TestCase {
         FSDataInputStream s2 = kosmosFileSystem.open(file1, 4096);
         int v;
 
+        v = s2.read();
+        assertEquals(v, 32);
+        v = s2.read();
+        assertEquals(v, 32);
+        v = s2.read();
+        assertEquals(v, 32);
         v = s2.read();
         assertEquals(v, 32);