Skip to content

Commit 473839f

Browse files
committed
BufferedFileChannelInputStream.available() should return 0 instead of -1
at the end of the stream
1 parent e9d28f7 commit 473839f

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ The <action> type attribute can be add,update,fix,remove.
7070
<action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid NullPointerException in ProxyInputStream.markSupported() when the underlying input stream is null.</action>
7171
<action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid NullPointerException in ProxyInputStream.mark(int) when the underlying input stream is null.</action>
7272
<action dev="ggregory" type="fix" due-to="Gary Gregory">BufferedFileChannelInputStream.available() returns 0 before any reads.</action>
73+
<action dev="ggregory" type="fix" due-to="Gary Gregory">BufferedFileChannelInputStream.available() should return 0 instead of -1 at the end of the stream.</action>
7374
<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>
7475
<action dev="ggregory" type="fix" due-to="Gary Gregory">CharSequenceInputStream.available() should return 0 after the stream is closed.</action>
7576
<action dev="ggregory" type="fix" due-to="Gary Gregory">BoundedInputStream.available() should return 0 when the stream is closed.</action>

src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public synchronized int available() throws IOException {
173173
return 0;
174174
}
175175
if (!refill()) {
176-
return EOF;
176+
return 0;
177177
}
178178
return byteBuffer.remaining();
179179
}

src/test/java/org/apache/commons/io/input/AbstractInputStreamTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ public void testAvailableAfterRead() throws Exception {
9191
}
9292
}
9393

94+
@Test
95+
public void testAvailableAtEnd() throws Exception {
96+
for (final InputStream inputStream : inputStreams) {
97+
IOUtils.consume(inputStream);
98+
assertEquals(0, inputStream.available());
99+
}
100+
}
101+
94102
@Test
95103
public void testBytesSkipped() throws IOException {
96104
for (final InputStream inputStream : inputStreams) {

0 commit comments

Comments
 (0)