1 package edu.rice.cs.util; 2 3 import java.io.*; 4 5 6 public class StreamRedirectThread extends Thread { 7 private final Reader in; 9 10 private final Writer out; 12 13 private static final int BUFFER_SIZE = 2048; 15 16 23 public StreamRedirectThread(String name, InputStream in, OutputStream out) { 24 super(name); 25 this.in = new InputStreamReader(in); 26 this.out = new OutputStreamWriter(out); 27 setPriority(Thread.MAX_PRIORITY - 1); 28 } 29 30 33 public void run() { 34 try { 35 char[] cbuf = new char[BUFFER_SIZE]; 36 int count; 37 while ((count = in.read(cbuf, 0, BUFFER_SIZE)) >= 0) { 38 out.write(cbuf, 0, count); 39 out.flush(); 40 } 41 out.flush(); 42 } 43 catch (IOException exc) { 44 } 46 } 47 } 48 | Popular Tags |