~ubuntu-branches/ubuntu/karmic/commons-io/karmic

« back to all changes in this revision

Viewing changes to src/java/org/apache/commons/io/output/TeeOutputStream.java

  • Committer: Bazaar Package Importer
  • Author(s): Wolfgang Baer
  • Date: 2005-10-16 13:44:21 UTC
  • Revision ID: james.westby@ubuntu.com-20051016134421-v2gfddy6iovz449t
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2001-2004 The Apache Software Foundation.
 
3
 * 
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
package org.apache.commons.io.output;
 
17
 
 
18
import java.io.IOException;
 
19
import java.io.OutputStream;
 
20
 
 
21
/**
 
22
 * Classic splitter of OutputStream. Named after the unix 'tee' 
 
23
 * command. It allows a stream to be branched off so there 
 
24
 * are now two streams.
 
25
 *
 
26
 * @author <a href="mailto:bayard@apache.org">Henri Yandell</a>
 
27
 * @version $Id: TeeOutputStream.java,v 1.6 2004/02/23 04:53:04 bayard Exp $
 
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) throws IOException {
 
52
        super.write(b, off, len);
 
53
        this.branch.write(b, off, len);
 
54
    }
 
55
 
 
56
    /** @see java.io.OutputStream#write(int) */
 
57
    public synchronized void write(int b) throws IOException {
 
58
        super.write(b);
 
59
        this.branch.write(b);
 
60
    }
 
61
 
 
62
    /**
 
63
     * Flushes both streams.
 
64
     *
 
65
     * @see java.io.OutputStream#flush()
 
66
     */
 
67
    public void flush() throws IOException {
 
68
        super.flush();
 
69
        this.branch.flush();
 
70
    }
 
71
 
 
72
    /**
 
73
     * Closes both streams. 
 
74
     *
 
75
     * @see java.io.OutputStream#close() 
 
76
     */
 
77
    public void close() throws IOException {
 
78
        super.close();
 
79
        this.branch.close();
 
80
    }
 
81
 
 
82
}