1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package uk.org.lidalia.sysoutslf4j.system;
26
27 import java.io.ByteArrayOutputStream;
28 import java.io.IOException;
29 import java.io.PrintStream;
30 import java.util.Locale;
31
32 import uk.org.lidalia.sysoutslf4j.common.LoggerAppender;
33 import uk.org.lidalia.sysoutslf4j.common.SLF4JPrintStream;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 public final class SLF4JPrintStreamImpl extends PrintStream implements SLF4JPrintStream {
97
98 private final PrintStream originalPrintStream;
99 private final SLF4JPrintStreamDelegate delegate;
100
101 SLF4JPrintStreamImpl(final PrintStream originalPrintStream, final SLF4JPrintStreamDelegate delegate) {
102
103
104 super(new ByteArrayOutputStream());
105 this.originalPrintStream = originalPrintStream;
106 this.delegate = delegate;
107 }
108
109 @Override
110 public synchronized void println(final String string) {
111 delegate.delegatePrintln(string);
112 }
113
114 @Override
115 public synchronized void println(final Object object) {
116 delegate.delegatePrintln(String.valueOf(object));
117 }
118
119 @Override
120 public synchronized void println() {
121 delegate.delegatePrintln("");
122 }
123
124 @Override
125 public synchronized void println(final boolean bool) {
126 delegate.delegatePrintln(String.valueOf(bool));
127 }
128
129 @Override
130 public synchronized void println(final char character) {
131 delegate.delegatePrintln(String.valueOf(character));
132 }
133
134 @Override
135 public synchronized void println(final char[] charArray) {
136 delegate.delegatePrintln(String.valueOf(charArray));
137 }
138
139 @Override
140 public synchronized void println(final double doub) {
141 delegate.delegatePrintln(String.valueOf(doub));
142 }
143
144 @Override
145 public synchronized void println(final float floa) {
146 delegate.delegatePrintln(String.valueOf(floa));
147 }
148
149 @Override
150 public synchronized void println(final int integer) {
151 delegate.delegatePrintln(String.valueOf(integer));
152 }
153
154 @Override
155 public synchronized void println(final long lon) {
156 delegate.delegatePrintln(String.valueOf(lon));
157 }
158
159 @Override
160 public synchronized PrintStream append(final char character) {
161 delegate.delegatePrint(String.valueOf(character));
162 return this;
163 }
164
165 @Override
166 public synchronized PrintStream append(final CharSequence csq, final int start, final int end) {
167 delegate.delegatePrint(csq.subSequence(start, end).toString());
168 return this;
169 }
170
171 @Override
172 public synchronized PrintStream append(final CharSequence csq) {
173 delegate.delegatePrint(csq.toString());
174 return this;
175 }
176
177 @Override
178 public boolean checkError() {
179 return originalPrintStream.checkError();
180 }
181
182 @Override
183 protected void setError() {
184 originalPrintStream.println("WARNING - calling setError on SLFJPrintStream does nothing");
185 }
186
187 @Override
188 public void close() {
189 originalPrintStream.close();
190 }
191
192 @Override
193 public void flush() {
194 originalPrintStream.flush();
195 }
196
197 @Override
198 public synchronized PrintStream format(final Locale locale, final String format, final Object... args) {
199 final String string = String.format(locale, format, args);
200 delegate.delegatePrint(string);
201 return this;
202 }
203
204 @Override
205 public synchronized PrintStream format(final String format, final Object... args) {
206 return format(Locale.getDefault(), format, args);
207 }
208
209 @Override
210 public synchronized void print(final boolean bool) {
211 delegate.delegatePrint(String.valueOf(bool));
212 }
213
214 @Override
215 public synchronized void print(final char character) {
216 delegate.delegatePrint(String.valueOf(character));
217 }
218
219 @Override
220 public synchronized void print(final char[] charArray) {
221 delegate.delegatePrint(String.valueOf(charArray));
222 }
223
224 @Override
225 public synchronized void print(final double doubl) {
226 delegate.delegatePrint(String.valueOf(doubl));
227 }
228
229 @Override
230 public synchronized void print(final float floa) {
231 delegate.delegatePrint(String.valueOf(floa));
232 }
233
234 @Override
235 public synchronized void print(final int integer) {
236 delegate.delegatePrint(String.valueOf(integer));
237 }
238
239 @Override
240 public synchronized void print(final long lon) {
241 delegate.delegatePrint(String.valueOf(lon));
242 }
243
244 @Override
245 public synchronized void print(final Object object) {
246 delegate.delegatePrint(String.valueOf(object));
247 }
248
249 @Override
250 public synchronized void print(final String string) {
251 delegate.delegatePrint(String.valueOf(string));
252 }
253
254 @Override
255 public synchronized PrintStream printf(final Locale locale, final String format, final Object... args) {
256 return format(locale, format, args);
257 }
258
259 @Override
260 public synchronized PrintStream printf(final String format, final Object... args) {
261 return format(format, args);
262 }
263
264 @Override
265 public void write(final byte[] buf, final int off, final int len) {
266 originalPrintStream.write(buf, off, len);
267 }
268
269 @Override
270 public void write(final int integer) {
271 originalPrintStream.write(integer);
272 }
273
274 @Override
275 public void write(final byte[] bytes) throws IOException {
276 originalPrintStream.write(bytes);
277 }
278
279 @Override
280 public void registerLoggerAppender(final Object loggerAppenderObject) {
281 final LoggerAppender loggerAppender = LoggerAppenderProxy.wrap(loggerAppenderObject);
282 delegate.registerLoggerAppender(loggerAppender);
283 }
284
285 @Override
286 public void deregisterLoggerAppender() {
287 delegate.deregisterLoggerAppender();
288 }
289
290 @Override
291 public PrintStream getOriginalPrintStream() {
292 return originalPrintStream;
293 }
294 }