01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.commons.io.output;
18:
19: import java.io.IOException;
20: import java.io.OutputStream;
21:
22: /**
23: * Classic splitter of OutputStream. Named after the unix 'tee'
24: * command. It allows a stream to be branched off so there
25: * are now two streams.
26: *
27: * @version $Id: TeeOutputStream.java 471628 2006-11-06 04:06:45Z bayard $
28: */
29: public class TeeOutputStream extends ProxyOutputStream {
30:
31: /** the second OutputStream to write to */
32: protected OutputStream branch;
33:
34: /**
35: * Constructs a TeeOutputStream.
36: * @param out the main OutputStream
37: * @param branch the second OutputStream
38: */
39: public TeeOutputStream(OutputStream out, OutputStream branch) {
40: super (out);
41: this .branch = branch;
42: }
43:
44: /** @see java.io.OutputStream#write(byte[]) */
45: public synchronized void write(byte[] b) throws IOException {
46: super .write(b);
47: this .branch.write(b);
48: }
49:
50: /** @see java.io.OutputStream#write(byte[], int, int) */
51: public synchronized void write(byte[] b, int off, int len)
52: throws IOException {
53: super .write(b, off, len);
54: this .branch.write(b, off, len);
55: }
56:
57: /** @see java.io.OutputStream#write(int) */
58: public synchronized void write(int b) throws IOException {
59: super .write(b);
60: this .branch.write(b);
61: }
62:
63: /**
64: * Flushes both streams.
65: *
66: * @see java.io.OutputStream#flush()
67: */
68: public void flush() throws IOException {
69: super .flush();
70: this .branch.flush();
71: }
72:
73: /**
74: * Closes both streams.
75: *
76: * @see java.io.OutputStream#close()
77: */
78: public void close() throws IOException {
79: super.close();
80: this.branch.close();
81: }
82:
83: }
|