1 5 package com.tc.process; 6 7 import java.io.IOException ; 8 import java.io.InputStream ; 9 import java.io.OutputStream ; 10 11 15 public class StreamCopier extends Thread { 16 17 protected final InputStream in; 18 protected final OutputStream out; 19 20 public StreamCopier(InputStream stream, OutputStream out) { 21 if ((stream == null) || (out == null)) { throw new AssertionError ("null streams not allowed"); } 22 23 this.in = stream; 24 this.out = out; 25 setName("Stream Copier"); 26 setDaemon(true); 27 } 28 29 public void run() { 30 byte[] buf = new byte[4096]; 31 32 try { 33 int read; 34 while ((read = in.read(buf)) >= 0) { 35 out.write(buf, 0, read); 36 } 37 } catch (IOException ioe) { 38 ioe.printStackTrace(); 39 } 40 } 41 42 } | Popular Tags |