blob: bce4f0f8702f7305db0e36d40c5efd62e709cb3e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
package bjc.everge;
import java.io.*;
import java.util.*;
/**
* An output stream that mirrors its contents to other streams.
*
* @author Ben Culkin
*
*/
public class MirrorOutputStream extends OutputStream {
private List<OutputStream> streams;
/**
* Create a new mirroring output stream.
*
* @param strams
* The output streams to mirror to.
*/
public MirrorOutputStream(OutputStream... strams) {
streams = new ArrayList<>();
for (OutputStream stram : strams) {
streams.add(stram);
}
}
@Override
public void close() throws IOException {
for (OutputStream stream : streams) {
stream.close();
}
}
@Override
public void flush() throws IOException {
for (OutputStream stream : streams) {
stream.flush();
}
}
@Override
public void write(byte[] ba) throws IOException {
for (OutputStream stream : streams) {
stream.write(ba);
}
}
@Override
public void write(byte[] ba, int off, int len) throws IOException {
for (OutputStream stream : streams) {
stream.write(ba, off, len);
}
}
@Override
public void write(int b) throws IOException {
for (OutputStream stream : streams) {
stream.write(b);
}
}
}
|