Skip to content

Commit 2838749

Browse files
author
Gary Gregory
committed
Add ClosedWriter.INSTANCE and deprected CLOSED_WRITER.
1 parent 0ca143f commit 2838749

4 files changed

Lines changed: 26 additions & 13 deletions

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ The <action> type attribute can be add,update,fix,remove.
8383
</action>
8484
<action dev="ggregory" type="add" due-to="Gary Gregory">
8585
Add ClosedOutputStream.INSTANCE and deprecate CLOSED_OUTPUT_STREAM.
86+
<action dev="ggregory" type="add" due-to="Gary Gregory">
87+
Add ClosedWriter.INSTANCE and deprected CLOSED_WRITER.
88+
</action>
8689
</action>
8790
<!-- UPDATE -->
8891
<action dev="ggregory" type="update" due-to="Dependabot">

src/main/java/org/apache/commons/io/output/CloseShieldWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public CloseShieldWriter(final Writer writer) {
6060
*/
6161
@Override
6262
public void close() {
63-
out = ClosedWriter.CLOSED_WRITER;
63+
out = ClosedWriter.INSTANCE;
6464
}
6565

6666
}

src/main/java/org/apache/commons/io/output/ClosedWriter.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,23 @@
3131
public class ClosedWriter extends Writer {
3232

3333
/**
34-
* A singleton.
34+
* The singleton instance.
35+
*
36+
* @since 2.12.0
3537
*/
36-
public static final ClosedWriter CLOSED_WRITER = new ClosedWriter();
38+
public static final ClosedWriter INSTANCE = new ClosedWriter();
3739

3840
/**
39-
* Throws an {@link IOException} to indicate that the writer is closed.
41+
* The singleton instance.
4042
*
41-
* @param cbuf ignored
42-
* @param off ignored
43-
* @param len ignored
44-
* @throws IOException always thrown
43+
* @deprecated Use {@link #INSTANCE}.
4544
*/
45+
@Deprecated
46+
public static final ClosedWriter CLOSED_WRITER = INSTANCE;
47+
4648
@Override
47-
public void write(final char[] cbuf, final int off, final int len) throws IOException {
48-
throw new IOException("write(" + new String(cbuf) + ", " + off + ", " + len + ") failed: stream is closed");
49+
public void close() throws IOException {
50+
// noop
4951
}
5052

5153
/**
@@ -58,8 +60,16 @@ public void flush() throws IOException {
5860
throw new IOException("flush() failed: stream is closed");
5961
}
6062

63+
/**
64+
* Throws an {@link IOException} to indicate that the writer is closed.
65+
*
66+
* @param cbuf ignored
67+
* @param off ignored
68+
* @param len ignored
69+
* @throws IOException always thrown
70+
*/
6171
@Override
62-
public void close() throws IOException {
63-
// noop
72+
public void write(final char[] cbuf, final int off, final int len) throws IOException {
73+
throw new IOException("write(" + new String(cbuf) + ", " + off + ", " + len + ") failed: stream is closed");
6474
}
6575
}

src/test/java/org/apache/commons/io/output/TaggedWriterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void testBrokenWriter() {
103103
@Test
104104
public void testOtherException() throws Exception {
105105
final IOException exception = new IOException("test exception");
106-
try (final TaggedWriter writer = new TaggedWriter(ClosedWriter.CLOSED_WRITER)) {
106+
try (final TaggedWriter writer = new TaggedWriter(ClosedWriter.INSTANCE)) {
107107

108108
assertFalse(writer.isCauseOf(exception));
109109
assertFalse(writer.isCauseOf(new TaggedIOException(exception, UUID.randomUUID())));

0 commit comments

Comments
 (0)