Skip to content

Commit 684c25b

Browse files
author
Gary Gregory
committed
[IO-630] Deprecate
`org.apache.commons.io.output.NullOutputStream.NullOutputStream()` in favor of `org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM`.
1 parent 633cd39 commit 684c25b

8 files changed

Lines changed: 21 additions & 7 deletions

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ The <action> type attribute can be add,update,fix,remove.
140140
<action issue="IO-628" dev="ggregory" type="update" due-to="Allon Mureinik">
141141
Migration to JUnit Jupiter #97.
142142
</action>
143+
<action issue="IO-630" dev="ggregory" type="update" due-to="Gary Gregory">
144+
Deprecate `org.apache.commons.io.output.NullOutputStream.NullOutputStream()` in favor of `org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM`.
145+
</action>
143146
</release>
144147

145148
<release version="2.6" date="2017-10-15" description="Java 7 required, Java 9 supported.">

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public static Checksum checksum(final File file, final Checksum checksum) throws
298298
throw new IllegalArgumentException("Checksums can't be computed on directories");
299299
}
300300
try (InputStream in = new CheckedInputStream(new FileInputStream(file), checksum)) {
301-
IOUtils.copy(in, new NullOutputStream());
301+
IOUtils.copy(in, NullOutputStream.NULL_OUTPUT_STREAM);
302302
}
303303
return checksum;
304304
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
*/
2929
public class NullOutputStream extends OutputStream {
3030

31+
/**
32+
* Deprecated in favor of {@link #NULL_OUTPUT_STREAM}.
33+
*
34+
* TODO: Will be private in 3.0.
35+
*
36+
* @deprecated Use {@link #NULL_OUTPUT_STREAM}.
37+
*/
38+
@Deprecated
39+
public NullOutputStream() {
40+
super();
41+
}
42+
3143
/**
3244
* A singleton.
3345
*/

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ public class NullPrintStream extends PrintStream {
3737
/**
3838
* Constructs an instance.
3939
*/
40-
@SuppressWarnings("resource")
4140
public NullPrintStream() {
42-
super(new NullOutputStream());
41+
super(NullOutputStream.NULL_OUTPUT_STREAM);
4342
}
4443

4544
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void testCopy_inputStreamToOutputStream() throws Exception {
8383
public void testCopy_inputStreamToOutputStream_IO84() throws Exception {
8484
final long size = (long)Integer.MAX_VALUE + (long)1;
8585
final InputStream in = new NullInputStream(size);
86-
final OutputStream out = new NullOutputStream();
86+
final OutputStream out = NullOutputStream.NULL_OUTPUT_STREAM;
8787

8888
// Test copy() method
8989
assertEquals(-1, IOUtils.copy(in, out));

src/test/java/org/apache/commons/io/input/CountingInputStreamTest.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
final NullInputStream mock = new NullInputStream(size);
7878
final CountingInputStream cis = new CountingInputStream(mock);
79-
final OutputStream out = new NullOutputStream();
79+
final OutputStream out = NullOutputStream.NULL_OUTPUT_STREAM;
8080

8181
// Test integer methods
8282
IOUtils.copyLarge(cis, out);

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

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

8383
final NullInputStream mock = new NullInputStream(size);
84-
final OutputStream nos = new NullOutputStream();
84+
final OutputStream nos = NullOutputStream.NULL_OUTPUT_STREAM;
8585
final CountingOutputStream cos = new CountingOutputStream(nos);
8686

8787
// Test integer methods

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private void process(final NullOutputStream nos) throws IOException {
4040

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

0 commit comments

Comments
 (0)