Skip to content

Commit ac5b3bb

Browse files
author
Gary Gregory
committed
Add NullOutputStream.INSTANCE and deprecate NULL_OUTPUT_STREAM.
1 parent 1362797 commit ac5b3bb

11 files changed

Lines changed: 25 additions & 12 deletions

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ The <action> type attribute can be add,update,fix,remove.
8787
<action dev="ggregory" type="add" due-to="Gary Gregory">
8888
Add ClosedWriter.INSTANCE and deprecate CLOSED_WRITER.
8989
</action>
90+
<action dev="ggregory" type="add" due-to="Gary Gregory">
91+
Add NullOutputStream.INSTANCE and deprecate NULL_OUTPUT_STREAM.
92+
</action>
9093
<!-- UPDATE -->
9194
<action dev="ggregory" type="update" due-to="Dependabot">
9295
Bump Maven Javadoc plugin from 3.2.0 to 3.3.0.

src/main/java/org/apache/commons/io/IOUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ public static void closeQuietly(final Writer writer) {
772772
*/
773773
public static long consume(final InputStream input)
774774
throws IOException {
775-
return copyLarge(input, NullOutputStream.NULL_OUTPUT_STREAM, getByteArray());
775+
return copyLarge(input, NullOutputStream.INSTANCE, getByteArray());
776776
}
777777

778778
/**

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,19 @@ public NullOutputStream() {
3939
}
4040

4141
/**
42-
* The singleton.
42+
* The singleton instance.
43+
*
44+
* @since 2.12.0
45+
*/
46+
public static final NullOutputStream INSTANCE = new NullOutputStream();
47+
48+
/**
49+
* The singleton instance.
50+
*
51+
* @deprecated Use {@link #INSTANCE}.
4352
*/
44-
public static final NullOutputStream NULL_OUTPUT_STREAM = new NullOutputStream();
53+
@Deprecated
54+
public static final NullOutputStream NULL_OUTPUT_STREAM = INSTANCE;
4555

4656
/**
4757
* Does nothing - output to {@code /dev/null}.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class NullPrintStream extends PrintStream {
3939
*/
4040
public NullPrintStream() {
4141
// Relies on the default charset which is OK since we are not actually writing.
42-
super(NullOutputStream.NULL_OUTPUT_STREAM);
42+
super(NullOutputStream.INSTANCE);
4343
}
4444

4545
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ThresholdingOutputStream extends OutputStream {
4040
/**
4141
* Noop output stream getter function.
4242
*/
43-
private static final IOFunction<ThresholdingOutputStream, OutputStream> NOOP_OS_GETTER = os -> NullOutputStream.NULL_OUTPUT_STREAM;
43+
private static final IOFunction<ThresholdingOutputStream, OutputStream> NOOP_OS_GETTER = os -> NullOutputStream.INSTANCE;
4444

4545
/**
4646
* The threshold at which the event will be triggered.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void testCopy_inputStreamToOutputStream() throws Exception {
8787
public void testCopy_inputStreamToOutputStream_IO84() throws Exception {
8888
final long size = (long)Integer.MAX_VALUE + (long)1;
8989
final InputStream in = new NullInputStream(size);
90-
final OutputStream out = NullOutputStream.NULL_OUTPUT_STREAM;
90+
final OutputStream out = NullOutputStream.INSTANCE;
9191

9292
// Test copy() method
9393
assertEquals(-1, IOUtils.copy(in, out));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ public void testConstants() {
500500
public void testConsume() throws Exception {
501501
final long size = (long) Integer.MAX_VALUE + (long) 1;
502502
final InputStream in = new NullInputStream(size);
503-
final OutputStream out = NullOutputStream.NULL_OUTPUT_STREAM;
503+
final OutputStream out = NullOutputStream.INSTANCE;
504504

505505
// Test copy() method
506506
assertEquals(-1, IOUtils.copy(in, out));

src/test/java/org/apache/commons/io/input/ObservableInputStreamTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private void testNotificationCallbacks(final int bufferSize) throws IOException
283283
try (final ObservableInputStream ois = new ObservableInputStream(new ByteArrayInputStream(buffer),
284284
lengthObserver, methodCountObserver)) {
285285
assertEquals(IOUtils.DEFAULT_BUFFER_SIZE,
286-
IOUtils.copy(ois, NullOutputStream.NULL_OUTPUT_STREAM, bufferSize));
286+
IOUtils.copy(ois, NullOutputStream.INSTANCE, bufferSize));
287287
}
288288
assertEquals(IOUtils.DEFAULT_BUFFER_SIZE, lengthObserver.getTotal());
289289
assertEquals(1, methodCountObserver.getClosedCount());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void testLargeFiles_IO84() throws Exception {
7676
final long size = (long) Integer.MAX_VALUE + (long) 1;
7777

7878
final NullInputStream mock = new NullInputStream(size);
79-
final CountingOutputStream cos = new CountingOutputStream(NullOutputStream.NULL_OUTPUT_STREAM);
79+
final CountingOutputStream cos = new CountingOutputStream(NullOutputStream.INSTANCE);
8080

8181
// Test integer methods
8282
IOUtils.copyLarge(mock, cos);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ private void process(final NullOutputStream nos) throws IOException {
4040

4141
@Test
4242
public void testNewInstance() throws IOException {
43-
try (final NullOutputStream nos = NullOutputStream.NULL_OUTPUT_STREAM) {
43+
try (final NullOutputStream nos = NullOutputStream.INSTANCE) {
4444
process(nos);
4545
}
4646
}
4747

4848
@Test
4949
public void testSingleton() throws IOException {
50-
try (final NullOutputStream nos = NullOutputStream.NULL_OUTPUT_STREAM) {
50+
try (final NullOutputStream nos = NullOutputStream.INSTANCE) {
5151
process(nos);
5252
}
5353
}

0 commit comments

Comments
 (0)