1 8 package org.codehaus.aspectwerkz.hook; 9 10 import java.io.InputStream ; 11 import java.io.OutputStream ; 12 13 19 class StreamRedirectThread extends Thread { 20 private static final int BUFFER_SIZE = 2048; 21 22 private static final int SLEEP = 5; 23 24 private InputStream is; 25 26 private OutputStream os; 27 28 public StreamRedirectThread(String name, InputStream is, OutputStream os) { 29 super(name); 30 setPriority(Thread.MAX_PRIORITY - 1); 31 this.is = is; 32 this.os = os; 33 } 34 35 public void run() { 36 byte[] buf = new byte[BUFFER_SIZE]; 37 int i; 38 try { 39 while ((i = is.read(buf)) > 0) { 40 os.write(buf, 0, i); 41 try { 42 Thread.sleep(SLEEP); 43 } catch (InterruptedException e) { 44 ; 45 } 46 } 47 } catch (Exception e) { 48 ; 49 } finally { 50 ; } 52 } 53 54 62 } | Popular Tags |