KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > util > io > TeeOutputStream


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 JavaDoc;
18 import java.io.OutputStream JavaDoc;
19
20 import org.apache.hivemind.util.Defense;
21
22 /**
23  * An output stream that copies bytes pushed through it to two other output streams.
24  *
25  * @author Howard M. Lewis Ship
26  * @since 4.0
27  */

28 public class TeeOutputStream extends OutputStream JavaDoc
29 {
30     private final OutputStream JavaDoc _os1;
31
32     private final OutputStream JavaDoc _os2;
33
34     public TeeOutputStream(OutputStream JavaDoc os1, OutputStream JavaDoc os2)
35     {
36         Defense.notNull(os1, "os1");
37         Defense.notNull(os2, "os2");
38
39         _os1 = os1;
40         _os2 = os2;
41     }
42
43     public void close() throws IOException JavaDoc
44     {
45         _os1.close();
46         _os2.close();
47     }
48
49     public void flush() throws IOException JavaDoc
50     {
51         _os1.flush();
52         _os2.flush();
53     }
54
55     public void write(byte[] b, int off, int len) throws IOException JavaDoc
56     {
57         _os1.write(b, off, len);
58         _os2.write(b, off, len);
59     }
60
61     public void write(byte[] b) throws IOException JavaDoc
62     {
63         _os1.write(b);
64         _os1.write(b);
65     }
66
67     public void write(int b) throws IOException JavaDoc
68     {
69         _os1.write(b);
70         _os2.write(b);
71     }
72 }
Popular Tags