Add ClosedWriter.INSTANCE and deprected CLOSED_WRITER.
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 640a553..5a3caf5 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -83,6 +83,9 @@
</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">
diff --git a/src/main/java/org/apache/commons/io/output/CloseShieldWriter.java b/src/main/java/org/apache/commons/io/output/CloseShieldWriter.java
index bd14c58..8d741ac 100644
--- a/src/main/java/org/apache/commons/io/output/CloseShieldWriter.java
+++ b/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;
}
}
diff --git a/src/main/java/org/apache/commons/io/output/ClosedWriter.java b/src/main/java/org/apache/commons/io/output/ClosedWriter.java
index 0d77beb..5721f57 100644
--- a/src/main/java/org/apache/commons/io/output/ClosedWriter.java
+++ b/src/main/java/org/apache/commons/io/output/ClosedWriter.java
@@ -31,21 +31,23 @@
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");
}
}
diff --git a/src/test/java/org/apache/commons/io/output/TaggedWriterTest.java b/src/test/java/org/apache/commons/io/output/TaggedWriterTest.java
index 1d2d848..e9e9559 100644
--- a/src/test/java/org/apache/commons/io/output/TaggedWriterTest.java
+++ b/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())));