Add ClosedInputStream.INSTANCE and deprecate CLOSED_INPUT_STREAM.
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -72,6 +72,9 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="add" due-to="Gary Gregory">
Add BrokenInputStream.INSTANCE.
</action>
+ <action dev="ggregory" type="add" due-to="Gary Gregory">
+ Add ClosedInputStream.INSTANCE and deprecate CLOSED_INPUT_STREAM.
+ </action>
<!-- UPDATE -->
<action dev="ggregory" type="update" due-to="Dependabot">
Bump Maven Javadoc plugin from 3.2.0 to 3.3.0.

MODIFY
src/main/java/org/apache/commons/io/input/AutoCloseInputStream.java
src/main/java/org/apache/commons/io/input/AutoCloseInputStream.java
@@ -63,7 +63,7 @@ public AutoCloseInputStream(final InputStream in) {
@Override
public void close() throws IOException {
in.close();
- in = ClosedInputStream.CLOSED_INPUT_STREAM;
+ in = ClosedInputStream.INSTANCE;
}
/**

MODIFY
src/main/java/org/apache/commons/io/input/CloseShieldInputStream.java
src/main/java/org/apache/commons/io/input/CloseShieldInputStream.java
@@ -61,7 +61,7 @@ public CloseShieldInputStream(final InputStream inputStream) {
*/
@Override
public void close() {
- in = ClosedInputStream.CLOSED_INPUT_STREAM;
+ in = ClosedInputStream.INSTANCE;
}
}

MODIFY
src/main/java/org/apache/commons/io/input/ClosedInputStream.java
src/main/java/org/apache/commons/io/input/ClosedInputStream.java
import java.io.InputStream;
/**
- * Closed input stream. This stream returns EOF to all attempts to read
- * something from the stream.
+ * Closed input stream. This stream returns EOF to all attempts to read something from the stream.
* <p>
- * Typically uses of this class include testing for corner cases in methods
- * that accept input streams and acting as a sentinel value instead of a
- * {@code null} input stream.
+ * Typically uses of this class include testing for corner cases in methods that accept input streams and acting as a
+ * sentinel value instead of a {@code null} input stream.
* </p>
*
* @since 1.4
public class ClosedInputStream extends InputStream {
/**
- * A singleton.
+ * The singleton instance.
+ *
+ * @since 2.12.0
+ */
+ public static final ClosedInputStream INSTANCE = new ClosedInputStream();
+
+ /**
+ * The singleton instance.
+ *
+ * @deprecated Use {@link #INSTANCE}.
*/
- public static final ClosedInputStream CLOSED_INPUT_STREAM = new ClosedInputStream();
+ @Deprecated
+ public static final ClosedInputStream CLOSED_INPUT_STREAM = INSTANCE;
/**
* Returns -1 to indicate that the stream is closed.

MODIFY
src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java
src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java
@@ -306,7 +306,7 @@ protected void writeToImpl(final OutputStream out) throws IOException {
final InputStreamConstructor<T> isConstructor) {
int remaining = count;
if (remaining == 0) {
- return ClosedInputStream.CLOSED_INPUT_STREAM;
+ return ClosedInputStream.INSTANCE;
}
final List<T> list = new ArrayList<>(buffers.size());
for (final byte[] buf : buffers) {

MODIFY
src/test/java/org/apache/commons/io/input/TaggedInputStreamTest.java
src/test/java/org/apache/commons/io/input/TaggedInputStreamTest.java
@Test
public void testEmptyStream() throws IOException {
- final InputStream stream = new TaggedInputStream(ClosedInputStream.CLOSED_INPUT_STREAM);
+ final InputStream stream = new TaggedInputStream(ClosedInputStream.INSTANCE);
assertEquals(0, stream.available());
assertEquals(-1, stream.read());
assertEquals(-1, stream.read(new byte[1]));
@@ -111,7 +111,7 @@ public void testBrokenStream() {
@Test
public void testOtherException() throws Exception {
final IOException exception = new IOException("test exception");
- final TaggedInputStream stream = new TaggedInputStream(ClosedInputStream.CLOSED_INPUT_STREAM);
+ final TaggedInputStream stream = new TaggedInputStream(ClosedInputStream.INSTANCE);
assertFalse(stream.isCauseOf(exception));
assertFalse(stream.isCauseOf(

MODIFY
src/test/java/org/apache/commons/io/input/UncheckedFilterInputStreamTest.java
src/test/java/org/apache/commons/io/input/UncheckedFilterInputStreamTest.java
@@ -125,7 +125,7 @@ public void testReadThrows() {
@Test
public void testResetThrows() {
- try (UncheckedFilterInputStream closedReader = UncheckedFilterInputStream.on(ClosedInputStream.CLOSED_INPUT_STREAM)) {
+ try (UncheckedFilterInputStream closedReader = UncheckedFilterInputStream.on(ClosedInputStream.INSTANCE)) {
closedReader.close();
assertThrows(UncheckedIOException.class, () -> brokenInputStream.reset());
}

Add ClosedInputStream.INSTANCE and deprecate CLOSED_INPUT_STREAM.