1 16 17 package org.apache.commons.launcher; 18 19 import java.io.InputStream ; 20 import java.io.IOException ; 21 import java.io.OutputStream ; 22 23 28 public class StreamConnector extends Thread { 29 30 32 35 private InputStream is = null; 36 37 40 private OutputStream os = null; 41 42 44 51 public StreamConnector(InputStream is, OutputStream os) { 52 53 this.is = is; 54 this.os = os; 55 56 } 57 58 60 64 public void run() { 65 66 if (is == null) 68 return; 69 70 try { 72 int bytesRead = 0; 73 byte[] buf = new byte[4096]; 74 while ((bytesRead = is.read(buf)) != -1) { 75 if (os != null && bytesRead > 0) { 76 os.write(buf, 0, bytesRead); 77 os.flush(); 78 } 79 yield(); 80 } 81 } catch (IOException e) {} 82 83 } 84 85 } 86 | Popular Tags |