1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.testUtil;
15
16 import java.io.PrintStream;
17 import java.util.ArrayList;
18 import java.util.Collections;
19 import java.util.List;
20
21
22
23
24
25
26
27
28
29 public class StringPrintStream extends PrintStream {
30
31 public static final String LINE_SEP = System.getProperty("line.separator");
32 PrintStream other;
33 boolean duplicate = false;
34
35 public List<String> stringList = Collections.synchronizedList(new ArrayList<String>());
36
37 public StringPrintStream(PrintStream ps, boolean duplicate) {
38 super(ps);
39 other = ps;
40 this.duplicate = duplicate;
41 }
42
43 public StringPrintStream(PrintStream ps) {
44 this(ps, false);
45 }
46
47 public void print(String s) {
48 if (duplicate)
49 other.print(s);
50 stringList.add(s);
51 }
52
53 public void println(String s) {
54 if (duplicate)
55 other.println(s);
56 stringList.add(s);
57 }
58
59 public void println(Object o) {
60 if (duplicate)
61 other.println(o);
62 stringList.add(o.toString());
63 }
64 }