This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 2838749  Add ClosedWriter.INSTANCE and deprected CLOSED_WRITER.
2838749 is described below

commit 2838749660e9ebd9a00460c824532333a88a1061
Author: Gary Gregory <[email protected]>
AuthorDate: Mon Jul 12 14:43:46 2021 -0400

    Add ClosedWriter.INSTANCE and deprected CLOSED_WRITER.
---
 src/changes/changes.xml                            |  3 ++
 .../commons/io/output/CloseShieldWriter.java       |  2 +-
 .../org/apache/commons/io/output/ClosedWriter.java | 32 ++++++++++++++--------
 .../apache/commons/io/output/TaggedWriterTest.java |  2 +-
 4 files changed, 26 insertions(+), 13 deletions(-)

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 @@ 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">
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 class CloseShieldWriter extends ProxyWriter {
      */
     @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 @@ import java.io.Writer;
 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 class ClosedWriter extends Writer {
         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 class TaggedWriterTest  {
     @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())));

Reply via email to