JAVA-23319 | Moving DualPrintStream (#14524)
* JAVA-23319 | moving DualPrintStream * JAVA-23319 | adding checkerror
This commit is contained in:
parent
746b11f454
commit
f90e26db1f
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue