1package org.bouncycastle.util.io;
2
3import java.io.IOException;
4import java.io.OutputStream;
5
6
7/**
8 * An output stream which copies anything written into it to another stream.
9 */
10public class TeeOutputStream
11    extends OutputStream
12{
13    private OutputStream output1;
14    private OutputStream output2;
15
16    /**
17     * Base constructor.
18     *
19     * @param output1 the output stream that is wrapped.
20     * @param output2 a secondary stream that anything written to output1 is also written to.
21     */
22    public TeeOutputStream(OutputStream output1, OutputStream output2)
23    {
24        this.output1 = output1;
25        this.output2 = output2;
26    }
27
28    public void write(byte[] buf)
29        throws IOException
30    {
31        this.output1.write(buf);
32        this.output2.write(buf);
33    }
34
35    public void write(byte[] buf, int off, int len)
36        throws IOException
37    {
38        this.output1.write(buf, off, len);
39        this.output2.write(buf, off, len);
40    }
41
42    public void write(int b)
43        throws IOException
44    {
45        this.output1.write(b);
46        this.output2.write(b);
47    }
48
49    public void flush()
50        throws IOException
51    {
52        this.output1.flush();
53        this.output2.flush();
54    }
55
56    public void close()
57        throws IOException
58    {
59        this.output1.close();
60        this.output2.close();
61    }
62}