01: package org.columba.core.io;
02:
03: import java.io.FilterInputStream;
04: import java.io.IOException;
05: import java.io.InputStream;
06: import java.io.OutputStream;
07:
08: public class PassiveCopyStream extends FilterInputStream {
09:
10: OutputStream out;
11:
12: public PassiveCopyStream(InputStream in, OutputStream out) {
13: super (in);
14:
15: this .out = out;
16: }
17:
18: /**
19: * {@inheritDoc}
20: */
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: /**
33: * {@inheritDoc}
34: */
35: @Override
36: public void close() throws IOException {
37: super .close();
38:
39: out.close();
40: }
41:
42: /**
43: * {@inheritDoc}
44: */
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: }
|