01: /**
02: * Copyright (C) 2004 France Telecom R&D
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */package org.objectweb.util.monolog.wrapper.common;
18:
19: import java.io.OutputStream;
20: import java.io.IOException;
21:
22: /**
23: * This Outstream implementation permits to switch the outStream at any time.
24: * It is interesting to switch between System.out and System.err dependeing on
25: * the message level.
26: *
27: * @author S.Chassande-Barrioz
28: */
29: public class OutputStreamSwitcher extends OutputStream {
30:
31: protected OutputStream currentOut;
32:
33: public OutputStreamSwitcher() {
34: currentOut = System.out;
35: }
36:
37: public OutputStreamSwitcher(OutputStream defaultOut) {
38: this .currentOut = defaultOut;
39: }
40:
41: public void switchOutput(OutputStream newOut) {
42: currentOut = newOut;
43: }
44:
45: public void write(byte b[]) throws IOException {
46: currentOut.write(b);
47: }
48:
49: public void write(byte b[], int off, int len) throws IOException {
50: currentOut.write(b, off, len);
51: }
52:
53: public void write(int b) throws IOException {
54: currentOut.write(b);
55: }
56:
57: public void flush() throws IOException {
58: currentOut.flush();
59: }
60:
61: public void close() throws IOException {
62: }
63: }
|