KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sshtools > ui > swing > ConsoleOutputStream


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sshtools.ui.swing;
21
22 import java.awt.Color JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.OutputStream JavaDoc;
25
26
27 /**
28  *
29  */

30 public class ConsoleOutputStream extends OutputStream JavaDoc {
31
32     // Private instace variables
33
private OutputStream JavaDoc oldSysOut;
34     private DebugConsole console;
35     private Color JavaDoc color;
36     
37     public ConsoleOutputStream(OutputStream JavaDoc oldSysOut, Color JavaDoc color, DebugConsole console) {
38         this.oldSysOut = oldSysOut;
39         this.console = console;
40         this.color = color;
41     }
42
43     /*
44      * (non-Javadoc)
45      *
46      * @see java.io.OutputStream#write(int)
47      */

48     public void write(int b) throws IOException JavaDoc {
49         console.append(String.valueOf((char) b), color);
50         if (oldSysOut != null) {
51             oldSysOut.write(b);
52         }
53     }
54
55     /*
56      * (non-Javadoc)
57      *
58      * @see java.io.OutputStream#write(byte[], int, int)
59      */

60     public void write(byte[] buf, int off, int len) throws IOException JavaDoc {
61         console.append(new String JavaDoc(buf, off, len), color);
62         if (oldSysOut != null) {
63             oldSysOut.write(buf, off, len);
64         }
65     }
66
67     /*
68      * (non-Javadoc)
69      *
70      * @see java.io.OutputStream#flush()
71      */

72     public void flush() throws IOException JavaDoc {
73         super.flush();
74         if (oldSysOut != null) {
75             oldSysOut.flush();
76         }
77     }
78 }
Popular Tags