Skip to content

Commit

Permalink
BufferedFileChannelInputStream.available() should return 0 instead of -1
Browse files Browse the repository at this point in the history
at the end of the stream
  • Loading branch information
garydgregory committed Sep 15, 2024
1 parent e9d28f7 commit 473839f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid NullPointerException in ProxyInputStream.markSupported() when the underlying input stream is null.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid NullPointerException in ProxyInputStream.mark(int) when the underlying input stream is null.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">BufferedFileChannelInputStream.available() returns 0 before any reads.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">BufferedFileChannelInputStream.available() should return 0 instead of -1 at the end of the stream.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">BufferedFileChannelInputStream.available() should return 0 when the stream is closed instead of throwing an exception.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">CharSequenceInputStream.available() should return 0 after the stream is closed.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">BoundedInputStream.available() should return 0 when the stream is closed.</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public synchronized int available() throws IOException {
return 0;
}
if (!refill()) {
return EOF;
return 0;
}
return byteBuffer.remaining();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ public void testAvailableAfterRead() throws Exception {
}
}

@Test
public void testAvailableAtEnd() throws Exception {
for (final InputStream inputStream : inputStreams) {
IOUtils.consume(inputStream);
assertEquals(0, inputStream.available());
}
}

@Test
public void testBytesSkipped() throws IOException {
for (final InputStream inputStream : inputStreams) {
Expand Down

0 comments on commit 473839f

Please sign in to comment.