KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > io > PassiveCopyStream


1 package org.columba.core.io;
2
3 import java.io.FilterInputStream JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.InputStream JavaDoc;
6 import java.io.OutputStream JavaDoc;
7
8 public class PassiveCopyStream extends FilterInputStream JavaDoc {
9
10     OutputStream JavaDoc out;
11     
12     public PassiveCopyStream(InputStream JavaDoc in, OutputStream JavaDoc out) {
13         super(in);
14         
15         this.out = out;
16     }
17
18     /**
19      * {@inheritDoc}
20      */

21     @Override JavaDoc
22     public int read(byte[] b, int off, int len) throws IOException JavaDoc {
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     /**
33      * {@inheritDoc}
34      */

35     @Override JavaDoc
36     public void close() throws IOException JavaDoc {
37         super.close();
38         
39         out.close();
40     }
41
42     /**
43      * {@inheritDoc}
44      */

45     @Override JavaDoc
46     public int read() throws IOException JavaDoc {
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