Add ClosedReader.INSTANCE and deprecate CLOSED_READER.
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -75,6 +75,9 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="add" due-to="Gary Gregory">
Add ClosedInputStream.INSTANCE and deprecate CLOSED_INPUT_STREAM.
</action>
+ <action dev="ggregory" type="add" due-to="Gary Gregory">
+ Add ClosedReader.INSTANCE and deprecate CLOSED_READER.
+ </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/CloseShieldReader.java
src/main/java/org/apache/commons/io/input/CloseShieldReader.java
@@ -60,7 +60,7 @@ public CloseShieldReader(final Reader reader) {
*/
@Override
public void close() {
- in = ClosedReader.CLOSED_READER;
+ in = ClosedReader.INSTANCE;
}
}

MODIFY
src/main/java/org/apache/commons/io/input/ClosedReader.java
src/main/java/org/apache/commons/io/input/ClosedReader.java
public class ClosedReader extends Reader {
/**
- * A singleton.
+ * The singleton instance.
+ *
+ * @since 2.12.0
+ */
+ public static final ClosedReader INSTANCE = new ClosedReader();
+
+ /**
+ * The singleton instance.
+ *
+ * @deprecated {@link #INSTANCE}.
*/
- public static final ClosedReader CLOSED_READER = new ClosedReader();
+ @Deprecated
+ public static final ClosedReader CLOSED_READER = INSTANCE;
/**
* Returns -1 to indicate that the stream is closed.

MODIFY
src/test/java/org/apache/commons/io/input/TaggedReaderTest.java
src/test/java/org/apache/commons/io/input/TaggedReaderTest.java
@Test
public void testEmptyReader() throws IOException {
- try (final Reader reader = new TaggedReader(ClosedReader.CLOSED_READER)) {
+ try (final Reader reader = new TaggedReader(ClosedReader.INSTANCE)) {
assertFalse(reader.ready());
assertEquals(-1, reader.read());
assertEquals(-1, reader.read(new char[1]));
@@ -109,7 +109,7 @@ public void testBrokenReader() {
@Test
public void testOtherException() throws Exception {
final IOException exception = new IOException("test exception");
- try (final TaggedReader reader = new TaggedReader(ClosedReader.CLOSED_READER)) {
+ try (final TaggedReader reader = new TaggedReader(ClosedReader.INSTANCE)) {
assertFalse(reader.isCauseOf(exception));
assertFalse(reader.isCauseOf(new TaggedIOException(exception, UUID.randomUUID())));

MODIFY
src/test/java/org/apache/commons/io/input/UncheckedBufferedReaderTest.java
src/test/java/org/apache/commons/io/input/UncheckedBufferedReaderTest.java
@@ -74,7 +74,7 @@ public void testMarkReset() {
@Test
public void testMarkThrows() {
- try (UncheckedBufferedReader closedReader = UncheckedBufferedReader.on(ClosedReader.CLOSED_READER)) {
+ try (UncheckedBufferedReader closedReader = UncheckedBufferedReader.on(ClosedReader.INSTANCE)) {
closedReader.close();
assertThrows(UncheckedIOException.class, () -> closedReader.mark(1));
}
@@ -191,7 +191,7 @@ public void testReadyThrows() {
@Test
public void testResetThrows() {
- try (UncheckedBufferedReader closedReader = UncheckedBufferedReader.on(ClosedReader.CLOSED_READER)) {
+ try (UncheckedBufferedReader closedReader = UncheckedBufferedReader.on(ClosedReader.INSTANCE)) {
closedReader.close();
assertThrows(UncheckedIOException.class, () -> ucBrokenReader.reset());
}

MODIFY
src/test/java/org/apache/commons/io/input/UncheckedFilterReaderTest.java
src/test/java/org/apache/commons/io/input/UncheckedFilterReaderTest.java
@@ -67,7 +67,7 @@ public void testMarkReset() {
@Test
public void testMarkThrows() {
- try (UncheckedFilterReader closedReader = UncheckedFilterReader.on(ClosedReader.CLOSED_READER)) {
+ try (UncheckedFilterReader closedReader = UncheckedFilterReader.on(ClosedReader.INSTANCE)) {
closedReader.close();
assertThrows(UncheckedIOException.class, () -> closedReader.mark(1));
}
@@ -170,7 +170,7 @@ public void testReadyThrows() {
@Test
public void testResetThrows() {
- try (UncheckedFilterReader closedReader = UncheckedFilterReader.on(ClosedReader.CLOSED_READER)) {
+ try (UncheckedFilterReader closedReader = UncheckedFilterReader.on(ClosedReader.INSTANCE)) {
closedReader.close();
assertThrows(UncheckedIOException.class, () -> ucBrokenReader.reset());
}

Add ClosedReader.INSTANCE and deprecate CLOSED_READER.