1 package com.ochafik.io; 2 import java.io.OutputStream; 3 4 import javax.swing.JTextArea; 5 import javax.swing.SwingUtilities; 6 public class JTextAreaOutputStream extends OutputStream { 7 JTextArea ta; 8 public JTextAreaOutputStream(JTextArea t) { 9 ta=t; 10 } 11 private class Appender implements Runnable { 12 public Appender(String st) { 13 string=st; 14 } 15 String string; 16 public void run() { 17 ta.append(string); 18 } 19 }; 20 public void close() {ta=null;} 21 public void write(int i) { 22 SwingUtilities.invokeLater(new Appender(new String(new byte[]{(byte)i}))); 23 } 24 public void write(byte b[]) { 25 SwingUtilities.invokeLater(new Appender(new String(b))); 26 } 27 public void write(byte b[],int s,int l) { 28 SwingUtilities.invokeLater(new Appender(new String(b,s,l))); 29 } 30 } 31