1 7 34 package com.sun.tools.example.trace; 35 36 import java.io.*; 37 38 45 class StreamRedirectThread extends Thread { 46 47 private final Reader in; 48 private final Writer out; 49 50 private static final int BUFFER_SIZE = 2048; 51 52 58 StreamRedirectThread(String name, InputStream in, OutputStream out) { 59 super(name); 60 this.in = new InputStreamReader(in); 61 this.out = new OutputStreamWriter(out); 62 setPriority(Thread.MAX_PRIORITY-1); 63 } 64 65 68 public void run() { 69 try { 70 char[] cbuf = new char[BUFFER_SIZE]; 71 int count; 72 while ((count = in.read(cbuf, 0, BUFFER_SIZE)) >= 0) { 73 out.write(cbuf, 0, count); 74 } 75 out.flush(); 76 } catch(IOException exc) { 77 System.err.println("Child I/O Transfer - " + exc); 78 } 79 } 80 } 81 | Popular Tags |