commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject commons-compress git commit: properly return -1 from read on EOF
Date Fri, 04 Nov 2016 15:43:39 GMT
Repository: commons-compress
Updated Branches:
  refs/heads/master 422160005 -> 46f57bf93


properly return -1 from read on EOF


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/46f57bf9
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/46f57bf9
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/46f57bf9

Branch: refs/heads/master
Commit: 46f57bf93d140737fcce830f83c962a309fa5a1a
Parents: 4221600
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Fri Nov 4 16:41:48 2016 +0100
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Fri Nov 4 16:43:26 2016 +0100

----------------------------------------------------------------------
 .../commons/compress/utils/SeekableInMemoryByteChannel.java      | 3 +++
 .../commons/compress/utils/SeekableInMemoryByteChannelTest.java  | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/46f57bf9/src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java
b/src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java
index 2057f17..75619b0 100644
--- a/src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java
+++ b/src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java
@@ -107,6 +107,9 @@ public class SeekableInMemoryByteChannel implements SeekableByteChannel
{
         repositionIfNecessary();
         int wanted = buf.remaining();
         int possible = size - position;
+        if (possible <= 0) {
+            return -1;
+        }
         if (wanted > possible) {
             wanted = possible;
         }

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/46f57bf9/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java
b/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java
index b552cf0..3e055b2 100644
--- a/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java
+++ b/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java
@@ -75,7 +75,7 @@ public class SeekableInMemoryByteChannelTest {
     }
 
     @Test
-    public void shouldReadNoDataWhenPositionAtTheEnd() throws IOException {
+    public void shouldSignalEOFWhenPositionAtTheEnd() throws IOException {
         //given
         SeekableInMemoryByteChannel c = new SeekableInMemoryByteChannel(testData);
         ByteBuffer readBuffer = ByteBuffer.allocate(testData.length);
@@ -84,7 +84,7 @@ public class SeekableInMemoryByteChannelTest {
         int readCount = c.read(readBuffer);
         //then
         assertEquals(0L, readBuffer.position());
-        assertEquals(0, readCount);
+        assertEquals(-1, readCount);
     }
 
     @Test(expected = ClosedChannelException.class)


Mime
View raw message