1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.testUtil;
15
16 import java.io.ByteArrayOutputStream;
17 import java.io.IOException;
18 import java.io.OutputStream;
19 import java.io.PrintStream;
20
21
22
23
24
25
26
27
28 public class TeeOutputStream extends OutputStream {
29
30 final PrintStream targetPS;
31 public final ByteArrayOutputStream baos = new ByteArrayOutputStream();
32
33 public TeeOutputStream(PrintStream targetPS) {
34
35 this.targetPS = targetPS;
36 }
37
38 public void write(int b) throws IOException {
39 baos.write(b);
40 if (targetPS != null) {
41 targetPS.write(b);
42 }
43 }
44
45 public String toString() {
46 return baos.toString();
47 }
48
49 public byte[] toByteArray() {
50 return baos.toByteArray();
51 }
52 }