1 package org.columba.core.io; 2 3 import java.io.FilterInputStream ; 4 import java.io.IOException ; 5 import java.io.InputStream ; 6 import java.io.OutputStream ; 7 8 public class PassiveCopyStream extends FilterInputStream { 9 10 OutputStream out; 11 12 public PassiveCopyStream(InputStream in, OutputStream out) { 13 super(in); 14 15 this.out = out; 16 } 17 18 21 @Override 22 public int read(byte[] b, int off, int len) throws IOException { 23 int read = super.read(b, off, len); 24 25 if( read != -1) { 26 out.write(b,off,read); 27 } 28 29 return read; 30 } 31 32 35 @Override 36 public void close() throws IOException { 37 super.close(); 38 39 out.close(); 40 } 41 42 45 @Override 46 public int read() throws IOException { 47 int result = super.read(); 48 49 if(result != -1) { 50 out.write(result); 51 } 52 53 return result; 54 } 55 56 57 58 59 } 60 | Popular Tags |