Mass removal of all Tabs (Style Warnings)
[aaf/authz.git] / misc / env / src / main / java / org / onap / aaf / misc / env / util / DoubleOutputStream.java
1 /**\r
2  * ============LICENSE_START====================================================\r
3  * org.onap.aaf\r
4  * ===========================================================================\r
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
6  * ===========================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END====================================================\r
19  *\r
20  */\r
21 \r
22 package org.onap.aaf.misc.env.util;\r
23 \r
24 import java.io.IOException;\r
25 import java.io.OutputStream;\r
26 \r
27 public class DoubleOutputStream extends OutputStream {\r
28     private OutputStream[] oss;\r
29     private boolean[] close;\r
30 \r
31     /**\r
32      * Create a Double Stream Writer\r
33      * Some Streams should not be closed by this object (i.e. System.out), therefore, mark them with booleans\r
34      */\r
35     public DoubleOutputStream(OutputStream a, boolean closeA, OutputStream b, boolean closeB) {\r
36         oss = new OutputStream[] {a,b};\r
37         close = new boolean[] {closeA,closeB};\r
38     }\r
39 \r
40     /**\r
41      * Write a single character.\r
42      * @throws IOException \r
43      */\r
44     @Override\r
45     public void write(int c) throws IOException {\r
46         for(OutputStream os : oss) {\r
47             os.write(c);\r
48         }\r
49     }\r
50 \r
51     /**\r
52      * Write a portion of an array of characters.\r
53      *\r
54      * @param  bbuf  Array of characters\r
55      * @param  off   Offset from which to start writing characters\r
56      * @param  len   Number of characters to write\r
57      * @throws IOException \r
58      */\r
59     @Override\r
60     public void write(byte bbuf[], int off, int len) throws IOException {\r
61         for(OutputStream os : oss) {\r
62             os.write(bbuf,off,len);\r
63         }\r
64     }\r
65 \r
66     @Override\r
67     public void write(byte[] b) throws IOException {\r
68         for(OutputStream os : oss) {\r
69             os.write(b);\r
70         }\r
71     }\r
72 \r
73     /* (non-Javadoc)\r
74      * @see java.io.OutputStream#close()\r
75      */\r
76     @Override\r
77     public void close() throws IOException {\r
78         for(int i=0;i<oss.length;++i) {\r
79             if(close[i]) {\r
80                 oss[i].close();\r
81             }\r
82         }\r
83     }\r
84 \r
85     /* (non-Javadoc)\r
86      * @see java.io.OutputStream#flush()\r
87      */\r
88     @Override\r
89     public void flush() throws IOException {\r
90         for(OutputStream os : oss) {\r
91             os.flush();\r
92         }\r
93     }\r
94 \r
95 \r
96 \r
97 }\r