// ReadToTextArea.java
//
// You may use and distribute this example. This program is 
// provided WITHOUT WARRANTY either expressed or implied.
//
// Copyright Henrik Björkman 1998
//
//
// History:
// 0.0 Created by Henrik Björkman 1999-09-07
//


import java.io.*;
import java.awt.*;

/**
 * This class reads from an input stream and writes 
 * everything read to an output stream (if any).
 */
public class ReadToTextArea extends Thread
{
  DataInputStream in;
  TextArea out;

  static void error(String str)
  {
    System.err.println("UpdateDir: " + str);
    System.exit(0);
  }

  public ReadToTextArea(InputStream in, TextArea out)
  {
    this.in=new DataInputStream(in);
    this.out=out;
    this.start();
  }
  
  public void run()
  {
    try
    {
      while (true) 
      {
        int ch=1;
        ch = in.read();
        if (ch<0) break;
        if (out!=null) out.appendText(""+(char)ch);
      }
    }
    catch(IOException e) 
    {
      error("IOException " + e);
    }
  }
}



