Skip to content

Commit fbc646f

Browse files
author
Gary Gregory
committed
Add NullWriter.INSTANCE and deprecate NULL_WRITER.
1 parent 16a8d5d commit fbc646f

5 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ The <action> type attribute can be add,update,fix,remove.
9393
<action dev="ggregory" type="add" due-to="Gary Gregory">
9494
Add NullPrintStream.INSTANCE and deprecate NULL_PRINT_STREAM.
9595
</action>
96+
<action dev="ggregory" type="add" due-to="Gary Gregory">
97+
Add NullWriter.INSTANCE and deprecate NULL_WRITER.
98+
</action>
9699
<!-- UPDATE -->
97100
<action dev="ggregory" type="update" due-to="Dependabot">
98101
Bump Maven Javadoc plugin from 3.2.0 to 3.3.0.

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,19 @@
2727
public class NullWriter extends Writer {
2828

2929
/**
30-
* A singleton.
30+
* The singleton instance.
31+
*
32+
* @since 2.12.0
3133
*/
32-
public static final NullWriter NULL_WRITER = new NullWriter();
34+
public static final NullWriter INSTANCE = new NullWriter();
35+
36+
/**
37+
* The singleton instance.
38+
*
39+
* @deprecated Use {@link #INSTANCE}.
40+
*/
41+
@Deprecated
42+
public static final NullWriter NULL_WRITER = INSTANCE;
3343

3444
/**
3545
* Constructs a new NullWriter.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class NullWriterTest {
2727
@Test
2828
public void testNull() {
2929
final char[] chars = { 'A', 'B', 'C' };
30-
try (final NullWriter writer = NullWriter.NULL_WRITER) {
30+
try (final NullWriter writer = NullWriter.INSTANCE) {
3131
writer.write(1);
3232
writer.write(chars);
3333
writer.write(chars, 1, 1);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,23 @@ public void writeCharArrayPartial() throws Exception {
107107

108108
@Test
109109
public void nullString() throws Exception {
110-
try (final ProxyWriter proxy = new ProxyWriter(NullWriter.NULL_WRITER)) {
110+
try (final ProxyWriter proxy = new ProxyWriter(NullWriter.INSTANCE)) {
111111
proxy.write((String) null);
112112
proxy.write((String) null, 0, 0);
113113
}
114114
}
115115

116116
@Test
117117
public void nullCharArray() throws Exception {
118-
try (final ProxyWriter proxy = new ProxyWriter(NullWriter.NULL_WRITER)) {
118+
try (final ProxyWriter proxy = new ProxyWriter(NullWriter.INSTANCE)) {
119119
proxy.write((char[]) null);
120120
proxy.write((char[]) null, 0, 0);
121121
}
122122
}
123123

124124
@Test
125125
public void nullCharSequence() throws Exception {
126-
try (final ProxyWriter proxy = new ProxyWriter(NullWriter.NULL_WRITER)) {
126+
try (final ProxyWriter proxy = new ProxyWriter(NullWriter.INSTANCE)) {
127127
proxy.append(null);
128128
}
129129
}

src/test/java/org/apache/commons/io/test/ThrowOnCloseWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class ThrowOnCloseWriter extends ProxyWriter {
3131
* Default ctor.
3232
*/
3333
public ThrowOnCloseWriter() {
34-
super(NullWriter.NULL_WRITER);
34+
super(NullWriter.INSTANCE);
3535
}
3636

3737
/**

0 commit comments

Comments
 (0)