You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2021/08/04 07:13:50 UTC

[GitHub] [commons-compress] PeterAlfredLee commented on a change in pull request #214: [COMPRESS-584] Fix IOUtils.readRange() can read more from a channel than asked for

PeterAlfredLee commented on a change in pull request #214:
URL: https://github.com/apache/commons-compress/pull/214#discussion_r682349198



##########
File path: src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java
##########
@@ -148,6 +148,25 @@ public void readRangeFromChannelDoesntReadMoreThanAskedFor() throws IOException
         }
     }
 
+    @Test
+    public void readRangeFromChannelDoesntReadMoreThanAskedForWhenItGotLessInFirstReadCall() throws IOException {
+        try (ReadableByteChannel in = new SeekableInMemoryByteChannel(new byte[] { 1, 2, 3, 4, 5 }) {
+            @Override
+            public int read(ByteBuffer buf) throws IOException {
+                // Read max 3 bytes at a time
+                ByteBuffer temp = ByteBuffer.allocate(Math.min(3, buf.remaining()));

Review comment:
       I think we can have a `final` here.
   Even through this is just a test, it's always appreciated if `final` is always used if possible.

##########
File path: src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java
##########
@@ -148,6 +148,25 @@ public void readRangeFromChannelDoesntReadMoreThanAskedFor() throws IOException
         }
     }
 
+    @Test
+    public void readRangeFromChannelDoesntReadMoreThanAskedForWhenItGotLessInFirstReadCall() throws IOException {
+        try (ReadableByteChannel in = new SeekableInMemoryByteChannel(new byte[] { 1, 2, 3, 4, 5 }) {
+            @Override
+            public int read(ByteBuffer buf) throws IOException {
+                // Read max 3 bytes at a time
+                ByteBuffer temp = ByteBuffer.allocate(Math.min(3, buf.remaining()));
+                int read = super.read(temp);
+                if (read > 0) {
+                    buf.put(temp.array(), 0, read);
+                }
+                return read;
+            }
+        }) {
+            byte[] read = IOUtils.readRange(in, 4);

Review comment:
       Same as above




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org