View Javadoc

1   /*
2    * Copyright (c) 2004-2007 Creative Sphere Limited.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *
10   *   Creative Sphere - initial API and implementation
11   *
12   */
13  package org.abstracthorizon.mercury.common.io;
14  
15  import java.io.IOException;
16  import java.io.OutputStream;
17  
18  /**
19   * This output stream writes out to both supplied streams at the same time.
20   *
21   * @author Daniel Sendula
22   */
23  public class StreamSplitter extends OutputStream {
24  
25      /** Fist stream */
26      protected OutputStream stream1;
27  
28      /** Second stream */
29      protected OutputStream stream2;
30  
31      /**
32       * Constructor
33       * @param stream1 first stream
34       * @param stream2 second stream
35       */
36      public StreamSplitter(OutputStream stream1, OutputStream stream2) {
37          this.stream1 = stream1;
38          this.stream2 = stream2;
39      }
40  
41      @Override
42      public void write(int b) throws IOException {
43          stream1.write(b);
44          stream2.write(b);
45      }
46  
47      @Override
48      public void write(byte[] b) throws IOException {
49          stream1.write(b);
50          stream2.write(b);
51      }
52  
53      @Override
54      public void write(byte[] b, int o, int l) throws IOException {
55          stream1.write(b, o, l);
56          stream2.write(b, o, l);
57      }
58  
59  }