Add a convenience NullPrintStream.
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -101,6 +101,9 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="IO-578" dev="ggregory" type="add" due-to="Mark Chesney">
Support java.nio.Path and non-default file systems for ReversedLinesFileReader (#62)
</action>
+ <action issue="IO-608" dev="ggregory" type="add" due-to="Gary Gregory">
+ Add a convenience NullPrintStream.
+ </action>
</release>
<release version="2.6" date="2017-10-15" description="Java 7 required, Java 9 supported.">

ADD
src/main/java/org/apache/commons/io/output/NullPrintStream.java
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.io.output;
+
+import java.io.PrintStream;
+
+/**
+ * This PrintStream writes all data to the famous <b>/dev/null</b>.
+ * <p>
+ * This print stream has no destination (file/socket etc.) and all bytes written to it are ignored and lost.
+ * </p>
+ *
+ * @since 2.7
+ */
+public class NullPrintStream extends PrintStream {
+
+ public static final NullPrintStream NULL_PRINT_STREAM = new NullPrintStream();
+
+ @SuppressWarnings("resource")
+ public NullPrintStream() {
+ super(new NullOutputStream());
+ }
+
+}

ADD
src/test/java/org/apache/commons/io/output/NullPrintStreamTest.java
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.io.output;
+
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+
+/**
+ * Really not a lot to do here, but checking that no Exceptions are thrown.
+ */
+public class NullPrintStreamTest {
+
+ private void process(final NullPrintStream nos) throws IOException {
+ nos.write("string".getBytes());
+ nos.write("some string".getBytes(), 3, 5);
+ nos.write(1);
+ nos.write(0x0f);
+ nos.flush();
+ nos.close();
+ nos.write("allowed".getBytes());
+ nos.write(255);
+ }
+
+ @Test
+ public void testNullNewInstance() throws IOException {
+ try (final NullPrintStream nos = new NullPrintStream()) {
+ process(nos);
+ }
+ }
+
+ @Test
+ public void testNullSingleton() throws IOException {
+ try (final NullPrintStream nos = NullPrintStream.NULL_PRINT_STREAM) {
+ process(nos);
+ }
+ }
+
+}

[IO-608] Add a convenience NullPrintStream.