Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TeeOutputStream |
|
| 1.0;1 |
1 | // Copyright 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package org.apache.tapestry.util.io; | |
16 | ||
17 | import java.io.IOException; | |
18 | import java.io.OutputStream; | |
19 | ||
20 | import org.apache.hivemind.util.Defense; | |
21 | ||
22 | /** | |
23 | * An output stream that copies bytes pushed through it to two other output | |
24 | * streams. | |
25 | * | |
26 | * @author Howard M. Lewis Ship | |
27 | * @since 4.0 | |
28 | */ | |
29 | public class TeeOutputStream extends OutputStream | |
30 | { | |
31 | ||
32 | private final OutputStream _os1; | |
33 | ||
34 | private final OutputStream _os2; | |
35 | ||
36 | public TeeOutputStream(OutputStream os1, OutputStream os2) | |
37 | 0 | { |
38 | 0 | Defense.notNull(os1, "os1"); |
39 | 0 | Defense.notNull(os2, "os2"); |
40 | ||
41 | 0 | _os1 = os1; |
42 | 0 | _os2 = os2; |
43 | 0 | } |
44 | ||
45 | public void close() | |
46 | throws IOException | |
47 | { | |
48 | 0 | _os1.close(); |
49 | 0 | _os2.close(); |
50 | 0 | } |
51 | ||
52 | public void flush() | |
53 | throws IOException | |
54 | { | |
55 | 0 | _os1.flush(); |
56 | 0 | _os2.flush(); |
57 | 0 | } |
58 | ||
59 | public void write(byte[] b, int off, int len) | |
60 | throws IOException | |
61 | { | |
62 | 0 | _os1.write(b, off, len); |
63 | 0 | _os2.write(b, off, len); |
64 | 0 | } |
65 | ||
66 | public void write(byte[] b) | |
67 | throws IOException | |
68 | { | |
69 | 0 | _os1.write(b); |
70 | 0 | _os1.write(b); |
71 | 0 | } |
72 | ||
73 | public void write(int b) | |
74 | throws IOException | |
75 | { | |
76 | 0 | _os1.write(b); |
77 | 0 | _os2.write(b); |
78 | 0 | } |
79 | } |