KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > editor > app > util > MultipleOutputStream


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.test.editor.app.util;
20
21 import java.io.OutputStream JavaDoc;
22 import java.util.Vector JavaDoc;
23
24 /**
25  *
26  * @author jlahoda
27  * @version
28  */

29 public class MultipleOutputStream extends java.io.OutputStream JavaDoc {
30
31     /** Creates new MultipleOutputStream */
32     private Vector JavaDoc streams;
33
34     public MultipleOutputStream() {
35         streams = new Vector JavaDoc(1, 1);
36     }
37
38     public MultipleOutputStream(Vector JavaDoc with) throws IllegalArgumentException JavaDoc {
39         this();
40         addStreams(with);
41     }
42
43     public MultipleOutputStream(OutputStream JavaDoc[] with) {
44         this();
45         addStreams(with);
46     }
47     
48     public void addStreams(Vector JavaDoc with) throws IllegalArgumentException JavaDoc {
49         for (int cntr = 0; cntr < with.size(); cntr++) {
50             if (!(with.elementAt(cntr) instanceof OutputStream JavaDoc))
51                 throw new IllegalArgumentException JavaDoc();
52             Object JavaDoc out = with.elementAt(cntr);
53             
54             if (out != null)
55                 streams.add(out);
56         };
57     }
58     
59     public void addStreams(OutputStream JavaDoc[] with) {
60         for (int cntr = 0; cntr < with.length; cntr++) {
61             if (with[cntr] != null)
62                 streams.add(with[cntr]);
63         };
64     }
65     
66     public void write(int b) throws java.io.IOException JavaDoc {
67         for (int cntr = 0; cntr < streams.size(); cntr++) {
68             OutputStream JavaDoc out = ((OutputStream JavaDoc)streams.elementAt(cntr));
69             
70             if (out != null)
71                 out.write(b);
72         };
73     }
74     
75     public void flush() throws java.io.IOException JavaDoc {
76         for (int cntr = 0; cntr < streams.size(); cntr++) {
77             OutputStream JavaDoc out = ((OutputStream JavaDoc)streams.elementAt(cntr));
78             
79             if (out != null)
80                 out.flush();
81         };
82     }
83
84     public void close() throws java.io.IOException JavaDoc {
85         for (int cntr = 0; cntr < streams.size(); cntr++) {
86             OutputStream JavaDoc out = ((OutputStream JavaDoc)streams.elementAt(cntr));
87             
88             if (out != null)
89                 out.close();
90         };
91     }
92
93 }
94
Popular Tags