diff --git a/core-java-modules/core-java-io-apis/src/main/java/com/baeldung/outputtofile/DualPrintStream.java b/core-java-modules/core-java-io-apis/src/main/java/com/baeldung/outputtofile/DualPrintStream.java new file mode 100644 index 0000000000..17e057aba9 --- /dev/null +++ b/core-java-modules/core-java-io-apis/src/main/java/com/baeldung/outputtofile/DualPrintStream.java @@ -0,0 +1,49 @@ +package com.baeldung.outputtofile; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; + +class DualPrintStream extends PrintStream { + private final PrintStream second; + + public DualPrintStream(OutputStream main, PrintStream second) { + super(main); + this.second = second; + } + + @Override + public void close() { + super.close(); + second.close(); + } + + @Override + public void flush() { + super.flush(); + second.flush(); + } + + @Override + public void write(byte[] buf, int off, int len) { + super.write(buf, off, len); + second.write(buf, off, len); + } + + @Override + public void write(int b) { + super.write(b); + second.write(b); + } + + @Override + public void write(byte[] b) throws IOException { + super.write(b); + second.write(b); + } + + @Override + public boolean checkError() { + return super.checkError() && second.checkError(); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-io-apis/src/test/java/com/baeldung/outputtofile/ConsoleOutputToFileUnitTest.java b/core-java-modules/core-java-io-apis/src/test/java/com/baeldung/outputtofile/ConsoleOutputToFileUnitTest.java index c7f643b148..24157d4efa 100644 --- a/core-java-modules/core-java-io-apis/src/test/java/com/baeldung/outputtofile/ConsoleOutputToFileUnitTest.java +++ b/core-java-modules/core-java-io-apis/src/test/java/com/baeldung/outputtofile/ConsoleOutputToFileUnitTest.java @@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertLinesMatch; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; -import java.io.OutputStream; import java.io.PrintStream; import java.nio.file.Files; import java.nio.file.Path; @@ -15,45 +14,6 @@ import org.junit.jupiter.api.io.TempDir; import com.google.common.collect.Lists; -class DualPrintStream extends PrintStream { - private final PrintStream second; - - public DualPrintStream(OutputStream main, PrintStream second) { - super(main); - this.second = second; - } - - @Override - public void close() { - super.close(); - second.close(); - } - - @Override - public void flush() { - super.flush(); - second.flush(); - } - - @Override - public void write(byte[] buf, int off, int len) { - super.write(buf, off, len); - second.write(buf, off, len); - } - - @Override - public void write(int b) { - super.write(b); - second.write(b); - } - - @Override - public void write(byte[] b) throws IOException { - super.write(b); - second.write(b); - } -} - public class ConsoleOutputToFileUnitTest { // @formatter:off