1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.util.io;
12
13 import java.io.IOException;
14 import java.io.OutputStream;
15
16
17
18
19
20
21 public class TeeOutputStream extends OutputStream {
22
23 private final OutputStream stream1;
24 private final OutputStream stream2;
25
26
27
28
29
30
31
32 public TeeOutputStream(OutputStream stream1, OutputStream stream2) {
33 this.stream1 = stream1;
34 this.stream2 = stream2;
35 }
36
37
38 @Override
39 public void write(byte[] buf) throws IOException {
40 this.stream1.write(buf);
41 this.stream2.write(buf);
42 }
43
44
45 @Override
46 public void write(byte[] buf, int off, int len) throws IOException {
47 this.stream1.write(buf, off, len);
48 this.stream2.write(buf, off, len);
49 }
50
51
52 @Override
53 public void write(int b) throws IOException {
54 this.stream1.write(b);
55 this.stream2.write(b);
56 }
57
58
59 @Override
60 public void flush() throws IOException {
61 this.stream1.flush();
62 this.stream2.flush();
63 }
64
65
66 @Override
67 public void close() throws IOException {
68 try {
69 this.stream1.close();
70 } finally {
71 this.stream2.close();
72 }
73 }
74 }