1 17 package org.apache.servicemix.jbi.util; 18 19 import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList; 20 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 31 public class MultiplexOutputStream extends OutputStream { 32 List streams = new CopyOnWriteArrayList(); 33 34 35 39 public void add(OutputStream os){ 40 streams.add(os); 41 } 42 43 47 public void remove(OutputStream os){ 48 streams.remove(os); 49 } 50 51 56 public synchronized void write(int b) throws IOException { 57 for (Iterator i = streams.iterator();i.hasNext();) { 58 OutputStream s = (OutputStream ) i.next(); 59 s.write(b); 60 } 61 } 62 63 70 public synchronized void write(byte b[], int off, int len) throws IOException { 71 for (Iterator i = streams.iterator();i.hasNext();) { 72 OutputStream s = (OutputStream ) i.next(); 73 s.write(b, off, len); 74 } 75 } 76 77 81 public void flush() throws IOException { 82 for (Iterator i = streams.iterator();i.hasNext();) { 83 OutputStream s = (OutputStream ) i.next(); 84 s.flush(); 85 } 86 } 87 88 92 public void close() throws IOException { 93 for (Iterator i = streams.iterator();i.hasNext();) { 94 OutputStream s = (OutputStream ) i.next(); 95 s.close(); 96 } 97 streams.clear(); 98 } 99 } 100 | Popular Tags |