1 | /*
|
---|
2 | * Copyright 2003-2005 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 | */
|
---|
17 |
|
---|
18 | package org.apache.tools.ant.util;
|
---|
19 |
|
---|
20 | import java.io.OutputStream;
|
---|
21 | import java.io.IOException;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * A simple T-piece to replicate an output stream into two separate streams
|
---|
25 | *
|
---|
26 | */
|
---|
27 | public class TeeOutputStream extends OutputStream {
|
---|
28 | private OutputStream left;
|
---|
29 | private OutputStream right;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Constructor for TeeOutputStream.
|
---|
33 | * @param left one of the output streams.
|
---|
34 | * @param right the other output stream.
|
---|
35 | */
|
---|
36 | public TeeOutputStream(OutputStream left, OutputStream right) {
|
---|
37 | this.left = left;
|
---|
38 | this.right = right;
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Close both output streams.
|
---|
43 | * @throws IOException on error.
|
---|
44 | */
|
---|
45 | public void close() throws IOException {
|
---|
46 | try {
|
---|
47 | left.close();
|
---|
48 | } finally {
|
---|
49 | right.close();
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Flush both output streams.
|
---|
55 | * @throws IOException on error
|
---|
56 | */
|
---|
57 | public void flush() throws IOException {
|
---|
58 | left.flush();
|
---|
59 | right.flush();
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Write a byte array to both output streams.
|
---|
64 | * @param b an array of bytes.
|
---|
65 | * @throws IOException on error.
|
---|
66 | */
|
---|
67 | public void write(byte[] b) throws IOException {
|
---|
68 | left.write(b);
|
---|
69 | right.write(b);
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Write a byte array to both output streams.
|
---|
74 | * @param b the data.
|
---|
75 | * @param off the start offset in the data.
|
---|
76 | * @param len the number of bytes to write.
|
---|
77 | * @throws IOException on error.
|
---|
78 | */
|
---|
79 | public void write(byte[] b, int off, int len) throws IOException {
|
---|
80 | left.write(b, off, len);
|
---|
81 | right.write(b, off, len);
|
---|
82 | }
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Write a byte to both output streams.
|
---|
86 | * @param b the byte to write.
|
---|
87 | * @throws IOException on error.
|
---|
88 | */
|
---|
89 | public void write(int b) throws IOException {
|
---|
90 | left.write(b);
|
---|
91 | right.write(b);
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|