Guest User

Untitled

a guest
Feb 24th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. class MultiplexOutputStream extends OutputStream {
  2.         private final OutputStream[] streams;
  3.  
  4.         public MultiplexOutputStream (OutputStream... streams) {
  5.             if (streams == null) throw new IllegalArgumentException("streams cannot be null.");
  6.             this.streams = streams;
  7.         }
  8.  
  9.         public void write (int b) throws IOException {
  10.             for (int i = 0; i < streams.length; i++) {
  11.                 synchronized (streams[i]) {
  12.                     streams[i].write(b);
  13.                 }
  14.             }
  15.         }
  16.  
  17.         public void write (byte[] b, int off, int len) throws IOException {
  18.             for (int i = 0; i < streams.length; i++) {
  19.                 synchronized (streams[i]) {
  20.                     streams[i].write(b, off, len);
  21.                 }
  22.             }
  23.         }
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment