Skip to content

Commit

Permalink
CharSequenceInputStream.available() should return 0 after the stream is
Browse files Browse the repository at this point in the history
closed

BoundedInputStream.available() return 0 after the stream is closed
  • Loading branch information
garydgregory committed Jul 7, 2024
1 parent e0e69af commit 0b07ef3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="add" due-to="Gary Gregory">Avoid NullPointerException in ProxyInputStream.available() when the underlying input stream is null.</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">BufferedFileChannelInputStream.available() returns 0 before any reads.</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">BufferedFileChannelInputStream.available() should return 0 when the stream is closed instead of throwing an exception.</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">CharSequenceInputStream.available() should return 0 after the stream is closed.</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">BoundedInputStream.available() should return 0 when the stream is closed.</action>
<!-- UPDATE -->
<action dev="ggregory" type="update" due-to="Dependabot">Bump tests commons.bytebuddy.version from 1.14.13 to 1.14.17 #615, #621, #631, #635.</action>
<action dev="ggregory" type="update" due-to="Dependabot">Bump tests commons-codec:commons-codec from 1.16.1 to 1.17.0.</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public int available() throws IOException {

@Override
public void close() throws IOException {
// noop
bBuf.position(bBuf.limit());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class CloseShieldInputStream extends ProxyInputStream {
* Constructs a proxy that only shields {@link System#in} from closing.
*
* @param inputStream the candidate input stream.
* @return the given stream or a proxy on {@link System#in}.
* @return the given stream or a proxy on {@link System#in}.
* @since 2.17.0
*/
public static InputStream systemIn(final InputStream inputStream) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ClosedInputStream extends InputStream {

/**
* Returns {@link #INSTANCE} if the given InputStream is null, otherwise returns the given input stream.
*
*
* @param in the InputStream to test.
* @return {@link #INSTANCE} if the given InputStream is null, otherwise returns the given input stream.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ public void testAvailable(final String csName) throws Exception {
}
}

@Test
public void testAvailableAfterClose() throws Exception {
final InputStream shadow;
try (InputStream in = CharSequenceInputStream.builder().setCharSequence("Hi").get()) {
assertTrue(in.available() > 0);
shadow = in;
}
assertEquals(0, shadow.available());
}

private void testAvailableRead(final String csName) throws Exception {
final String input = "test";
try (InputStream r = new CharSequenceInputStream(input, csName)) {
Expand Down

0 comments on commit 0b07ef3

Please sign in to comment.