Ejemplo n.º 1
0
  public synchronized void run() {

    byte[] buffer = new byte[BUFFER_SIZE];

    for (; ; ) {
      try {
        this.wait(100);
      } catch (InterruptedException ie) {
      }

      int len = 0;
      try {
        int noBytes = pin.available();

        if (noBytes > 0) {
          len = pin.read(buffer, 0, Math.min(noBytes, BUFFER_SIZE));
          if (len > 0) {
            jTextArea.append(new String(buffer, 0, len));
            jTextArea.setCaretPosition(jTextArea.getText().length());
          }
        }
      } catch (IOException ioe) {
        throw new UIError("Unable to read from input stream! " + ioe.getMessage());
      }
    }
  }
Ejemplo n.º 2
0
 public synchronized String readLine(PipedInputStream in) throws IOException {
   String input = "";
   do {
     int available = in.available();
     if (available == 0) {
       break;
     }
     byte b[] = new byte[available];
     in.read(b);
     input = input + new String(b, 0, b.length);
   } while (!input.endsWith("\n") && !input.endsWith("\r\n") && !quit);
   return input;
 }