KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > monolog > wrapper > common > OutputStreamSwitcher


1 /**
2  * Copyright (C) 2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * 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  */

18 package org.objectweb.util.monolog.wrapper.common;
19
20 import java.io.OutputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22
23 /**
24  * This Outstream implementation permits to switch the outStream at any time.
25  * It is interesting to switch between System.out and System.err dependeing on
26  * the message level.
27  *
28  * @author S.Chassande-Barrioz
29  */

30 public class OutputStreamSwitcher extends OutputStream JavaDoc {
31
32     protected OutputStream JavaDoc currentOut;
33
34     public OutputStreamSwitcher() {
35         currentOut = System.out;
36     }
37
38     public OutputStreamSwitcher(OutputStream JavaDoc defaultOut) {
39         this.currentOut = defaultOut;
40     }
41
42     public void switchOutput(OutputStream JavaDoc newOut) {
43         currentOut = newOut;
44     }
45
46     public void write(byte b[]) throws IOException JavaDoc {
47         currentOut.write(b);
48     }
49
50     public void write(byte b[], int off, int len) throws IOException JavaDoc {
51         currentOut.write(b, off, len);
52     }
53
54     public void write(int b) throws IOException JavaDoc {
55         currentOut.write(b);
56     }
57
58     public void flush() throws IOException JavaDoc {
59         currentOut.flush();
60     }
61
62     public void close() throws IOException JavaDoc {
63     }
64 }
65
Popular Tags