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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]