flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johnyru...@apache.org
Subject flume git commit: FLUME-2593. ResettableFileInputStream returns negate values from read() method
Date Fri, 23 Oct 2015 01:40:16 GMT
Repository: flume
Updated Branches:
  refs/heads/trunk d6bf08b54 -> 0e40e8311


FLUME-2593. ResettableFileInputStream returns negate values from read() method

(Miroslav Holubec via Johny Rufus)


Project: http://git-wip-us.apache.org/repos/asf/flume/repo
Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/0e40e831
Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/0e40e831
Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/0e40e831

Branch: refs/heads/trunk
Commit: 0e40e831108f34b5bc6d01bf1ffa9efae330ea82
Parents: d6bf08b
Author: Johny Rufus <johnyrufus@apache.org>
Authored: Thu Oct 22 18:35:38 2015 -0700
Committer: Johny Rufus <johnyrufus@apache.org>
Committed: Thu Oct 22 18:35:38 2015 -0700

----------------------------------------------------------------------
 .../ResettableFileInputStream.java              |  2 +-
 .../TestResettableFileInputStream.java          | 23 ++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flume/blob/0e40e831/flume-ng-core/src/main/java/org/apache/flume/serialization/ResettableFileInputStream.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/main/java/org/apache/flume/serialization/ResettableFileInputStream.java
b/flume-ng-core/src/main/java/org/apache/flume/serialization/ResettableFileInputStream.java
index 622c09f..618913e 100644
--- a/flume-ng-core/src/main/java/org/apache/flume/serialization/ResettableFileInputStream.java
+++ b/flume-ng-core/src/main/java/org/apache/flume/serialization/ResettableFileInputStream.java
@@ -224,7 +224,7 @@ public class ResettableFileInputStream extends ResettableInputStream
     } else if (len == 0) {
       return -1;
     } else {
-      return byteBuf[0];
+      return byteBuf[0] & 0xFF;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/flume/blob/0e40e831/flume-ng-core/src/test/java/org/apache/flume/serialization/TestResettableFileInputStream.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/serialization/TestResettableFileInputStream.java
b/flume-ng-core/src/test/java/org/apache/flume/serialization/TestResettableFileInputStream.java
index 2c559db..631bdfe 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/serialization/TestResettableFileInputStream.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/serialization/TestResettableFileInputStream.java
@@ -87,6 +87,29 @@ public class TestResettableFileInputStream {
     in.close();
   }
 
+  /**
+   * Ensure that we can simply read bytes from a file using InputStream.read() method.
+   * @throws IOException
+   */
+  @Test
+  public void testReadByte() throws IOException {
+    byte[] bytes = new byte[255];
+    for (int i = 0; i < 255; i++) {
+      bytes[i] = (byte) i;
+    }
+
+    Files.write(bytes, file);
+
+    PositionTracker tracker = new DurablePositionTracker(meta, file.getPath());
+    ResettableInputStream in = new ResettableFileInputStream(file, tracker);
+
+    for (int i = 0; i < 255; i++) {
+      assertEquals(i, in.read());
+    }
+    assertEquals(-1, in.read());
+
+    in.close();
+  }
 
   /**
    * Ensure that we can process lines that contain multi byte characters in weird places


Mime
View raw message