001 package com.ochafik.io; 002 import java.io.OutputStream; 003 004 import javax.swing.JTextArea; 005 import javax.swing.SwingUtilities; 006 public class JTextAreaOutputStream extends OutputStream { 007 JTextArea ta; 008 public JTextAreaOutputStream(JTextArea t) { 009 ta=t; 010 } 011 private class Appender implements Runnable { 012 public Appender(String st) { 013 string=st; 014 } 015 String string; 016 public void run() { 017 ta.append(string); 018 } 019 }; 020 public void close() {ta=null;} 021 public void write(int i) { 022 SwingUtilities.invokeLater(new Appender(new String(new byte[]{(byte)i}))); 023 } 024 public void write(byte b[]) { 025 SwingUtilities.invokeLater(new Appender(new String(b))); 026 } 027 public void write(byte b[],int s,int l) { 028 SwingUtilities.invokeLater(new Appender(new String(b,s,l))); 029 } 030 } 031