Skip to content

Commit 982bc5e

Browse files
author
Gary Gregory
committed
Add ClosedInputStream.INSTANCE and deprecate CLOSED_INPUT_STREAM.
1 parent b8b0766 commit 982bc5e

7 files changed

Lines changed: 24 additions & 13 deletions

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ The <action> type attribute can be add,update,fix,remove.
7272
<action dev="ggregory" type="add" due-to="Gary Gregory">
7373
Add BrokenInputStream.INSTANCE.
7474
</action>
75+
<action dev="ggregory" type="add" due-to="Gary Gregory">
76+
Add ClosedInputStream.INSTANCE and deprecate CLOSED_INPUT_STREAM.
77+
</action>
7578
<!-- UPDATE -->
7679
<action dev="ggregory" type="update" due-to="Dependabot">
7780
Bump Maven Javadoc plugin from 3.2.0 to 3.3.0.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public AutoCloseInputStream(final InputStream in) {
6363
@Override
6464
public void close() throws IOException {
6565
in.close();
66-
in = ClosedInputStream.CLOSED_INPUT_STREAM;
66+
in = ClosedInputStream.INSTANCE;
6767
}
6868

6969
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public CloseShieldInputStream(final InputStream inputStream) {
6161
*/
6262
@Override
6363
public void close() {
64-
in = ClosedInputStream.CLOSED_INPUT_STREAM;
64+
in = ClosedInputStream.INSTANCE;
6565
}
6666

6767
}

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,30 @@
2121
import java.io.InputStream;
2222

2323
/**
24-
* Closed input stream. This stream returns EOF to all attempts to read
25-
* something from the stream.
24+
* Closed input stream. This stream returns EOF to all attempts to read something from the stream.
2625
* <p>
27-
* Typically uses of this class include testing for corner cases in methods
28-
* that accept input streams and acting as a sentinel value instead of a
29-
* {@code null} input stream.
26+
* Typically uses of this class include testing for corner cases in methods that accept input streams and acting as a
27+
* sentinel value instead of a {@code null} input stream.
3028
* </p>
3129
*
3230
* @since 1.4
3331
*/
3432
public class ClosedInputStream extends InputStream {
3533

3634
/**
37-
* A singleton.
35+
* The singleton instance.
36+
*
37+
* @since 2.12.0
38+
*/
39+
public static final ClosedInputStream INSTANCE = new ClosedInputStream();
40+
41+
/**
42+
* The singleton instance.
43+
*
44+
* @deprecated Use {@link #INSTANCE}.
3845
*/
39-
public static final ClosedInputStream CLOSED_INPUT_STREAM = new ClosedInputStream();
46+
@Deprecated
47+
public static final ClosedInputStream CLOSED_INPUT_STREAM = INSTANCE;
4048

4149
/**
4250
* Returns -1 to indicate that the stream is closed.

src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ protected <T extends InputStream> InputStream toInputStream(
306306
final InputStreamConstructor<T> isConstructor) {
307307
int remaining = count;
308308
if (remaining == 0) {
309-
return ClosedInputStream.CLOSED_INPUT_STREAM;
309+
return ClosedInputStream.INSTANCE;
310310
}
311311
final List<T> list = new ArrayList<>(buffers.size());
312312
for (final byte[] buf : buffers) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class TaggedInputStreamTest {
3636

3737
@Test
3838
public void testEmptyStream() throws IOException {
39-
final InputStream stream = new TaggedInputStream(ClosedInputStream.CLOSED_INPUT_STREAM);
39+
final InputStream stream = new TaggedInputStream(ClosedInputStream.INSTANCE);
4040
assertEquals(0, stream.available());
4141
assertEquals(-1, stream.read());
4242
assertEquals(-1, stream.read(new byte[1]));
@@ -111,7 +111,7 @@ public void testBrokenStream() {
111111
@Test
112112
public void testOtherException() throws Exception {
113113
final IOException exception = new IOException("test exception");
114-
final TaggedInputStream stream = new TaggedInputStream(ClosedInputStream.CLOSED_INPUT_STREAM);
114+
final TaggedInputStream stream = new TaggedInputStream(ClosedInputStream.INSTANCE);
115115

116116
assertFalse(stream.isCauseOf(exception));
117117
assertFalse(stream.isCauseOf(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public void testReadThrows() {
125125

126126
@Test
127127
public void testResetThrows() {
128-
try (UncheckedFilterInputStream closedReader = UncheckedFilterInputStream.on(ClosedInputStream.CLOSED_INPUT_STREAM)) {
128+
try (UncheckedFilterInputStream closedReader = UncheckedFilterInputStream.on(ClosedInputStream.INSTANCE)) {
129129
closedReader.close();
130130
assertThrows(UncheckedIOException.class, () -> brokenInputStream.reset());
131131
}

0 commit comments

Comments
 (0)