Add ClosedWriter.INSTANCE and deprected CLOSED_WRITER.
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -83,6 +83,9 @@ The <action> type attribute can be add,update,fix,remove.
</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">
Add ClosedOutputStream.INSTANCE and deprecate CLOSED_OUTPUT_STREAM.
+ <action dev="ggregory" type="add" due-to="Gary Gregory">
+ Add ClosedWriter.INSTANCE and deprected CLOSED_WRITER.
+ </action>
</action>
<!-- UPDATE -->
<action dev="ggregory" type="update" due-to="Dependabot">

MODIFY
src/main/java/org/apache/commons/io/output/CloseShieldWriter.java
src/main/java/org/apache/commons/io/output/CloseShieldWriter.java
@@ -60,7 +60,7 @@ public CloseShieldWriter(final Writer writer) {
*/
@Override
public void close() {
- out = ClosedWriter.CLOSED_WRITER;
+ out = ClosedWriter.INSTANCE;
}
}

MODIFY
src/main/java/org/apache/commons/io/output/ClosedWriter.java
src/main/java/org/apache/commons/io/output/ClosedWriter.java
public class ClosedWriter extends Writer {
/**
- * A singleton.
+ * The singleton instance.
+ *
+ * @since 2.12.0
*/
- public static final ClosedWriter CLOSED_WRITER = new ClosedWriter();
+ public static final ClosedWriter INSTANCE = new ClosedWriter();
/**
- * Throws an {@link IOException} to indicate that the writer is closed.
+ * The singleton instance.
*
- * @param cbuf ignored
- * @param off ignored
- * @param len ignored
- * @throws IOException always thrown
+ * @deprecated Use {@link #INSTANCE}.
*/
+ @Deprecated
+ public static final ClosedWriter CLOSED_WRITER = INSTANCE;
+
@Override
- public void write(final char[] cbuf, final int off, final int len) throws IOException {
- throw new IOException("write(" + new String(cbuf) + ", " + off + ", " + len + ") failed: stream is closed");
+ public void close() throws IOException {
+ // noop
}
/**
@@ -58,8 +60,16 @@ public void flush() throws IOException {
throw new IOException("flush() failed: stream is closed");
}
+ /**
+ * Throws an {@link IOException} to indicate that the writer is closed.
+ *
+ * @param cbuf ignored
+ * @param off ignored
+ * @param len ignored
+ * @throws IOException always thrown
+ */
@Override
- public void close() throws IOException {
- // noop
+ public void write(final char[] cbuf, final int off, final int len) throws IOException {
+ throw new IOException("write(" + new String(cbuf) + ", " + off + ", " + len + ") failed: stream is closed");
}
}

MODIFY
src/test/java/org/apache/commons/io/output/TaggedWriterTest.java
src/test/java/org/apache/commons/io/output/TaggedWriterTest.java
@@ -103,7 +103,7 @@ public void testBrokenWriter() {
@Test
public void testOtherException() throws Exception {
final IOException exception = new IOException("test exception");
- try (final TaggedWriter writer = new TaggedWriter(ClosedWriter.CLOSED_WRITER)) {
+ try (final TaggedWriter writer = new TaggedWriter(ClosedWriter.INSTANCE)) {
assertFalse(writer.isCauseOf(exception));
assertFalse(writer.isCauseOf(new TaggedIOException(exception, UUID.randomUUID())));

Add ClosedWriter.INSTANCE and deprected CLOSED_WRITER.