1 19 20 package com.sshtools.ui.swing; 21 22 import java.awt.Color ; 23 import java.io.IOException ; 24 import java.io.OutputStream ; 25 26 27 30 public class ConsoleOutputStream extends OutputStream { 31 32 private OutputStream oldSysOut; 34 private DebugConsole console; 35 private Color color; 36 37 public ConsoleOutputStream(OutputStream oldSysOut, Color color, DebugConsole console) { 38 this.oldSysOut = oldSysOut; 39 this.console = console; 40 this.color = color; 41 } 42 43 48 public void write(int b) throws IOException { 49 console.append(String.valueOf((char) b), color); 50 if (oldSysOut != null) { 51 oldSysOut.write(b); 52 } 53 } 54 55 60 public void write(byte[] buf, int off, int len) throws IOException { 61 console.append(new String (buf, off, len), color); 62 if (oldSysOut != null) { 63 oldSysOut.write(buf, off, len); 64 } 65 } 66 67 72 public void flush() throws IOException { 73 super.flush(); 74 if (oldSysOut != null) { 75 oldSysOut.flush(); 76 } 77 } 78 } | Popular Tags |