CloneOutputStream.java

  1. package com.github.casperjs.casperjsrunner.cmd;

  2. import static com.google.common.collect.Lists.newArrayList;

  3. import java.io.IOException;
  4. import java.io.OutputStream;
  5. import java.util.List;

  6. public class CloneOutputStream extends OutputStream {

  7.     private List<OutputStream> streams;

  8.     public CloneOutputStream(final OutputStream... streams) {
  9.         this.streams = newArrayList(streams);
  10.     }

  11.     @Override
  12.     public void write(final int b) throws IOException {
  13.         for (final OutputStream stream : streams) {
  14.             stream.write(b);
  15.         }
  16.     }

  17.     @Override
  18.     public void write(final byte[] b) throws IOException {
  19.         for (final OutputStream stream : streams) {
  20.             stream.write(b);
  21.         }
  22.     }

  23.     @Override
  24.     public void write(final byte[] b, final int off, final int len) throws IOException {
  25.         for (final OutputStream stream : streams) {
  26.             stream.write(b, off, len);
  27.         }
  28.     }

  29.     @Override
  30.     public void flush() throws IOException {
  31.         for (final OutputStream stream : streams) {
  32.             stream.flush();
  33.         }
  34.     }

  35.     @Override
  36.     public void close() throws IOException {
  37.         for (final OutputStream stream : streams) {
  38.             stream.close();
  39.         }
  40.     }

  41. }