1 19 package org.netbeans.test.editor.app.util; 20 21 import java.io.OutputStream ; 22 import java.util.Vector ; 23 24 29 public class MultipleOutputStream extends java.io.OutputStream { 30 31 32 private Vector streams; 33 34 public MultipleOutputStream() { 35 streams = new Vector (1, 1); 36 } 37 38 public MultipleOutputStream(Vector with) throws IllegalArgumentException { 39 this(); 40 addStreams(with); 41 } 42 43 public MultipleOutputStream(OutputStream [] with) { 44 this(); 45 addStreams(with); 46 } 47 48 public void addStreams(Vector with) throws IllegalArgumentException { 49 for (int cntr = 0; cntr < with.size(); cntr++) { 50 if (!(with.elementAt(cntr) instanceof OutputStream )) 51 throw new IllegalArgumentException (); 52 Object out = with.elementAt(cntr); 53 54 if (out != null) 55 streams.add(out); 56 }; 57 } 58 59 public void addStreams(OutputStream [] with) { 60 for (int cntr = 0; cntr < with.length; cntr++) { 61 if (with[cntr] != null) 62 streams.add(with[cntr]); 63 }; 64 } 65 66 public void write(int b) throws java.io.IOException { 67 for (int cntr = 0; cntr < streams.size(); cntr++) { 68 OutputStream out = ((OutputStream )streams.elementAt(cntr)); 69 70 if (out != null) 71 out.write(b); 72 }; 73 } 74 75 public void flush() throws java.io.IOException { 76 for (int cntr = 0; cntr < streams.size(); cntr++) { 77 OutputStream out = ((OutputStream )streams.elementAt(cntr)); 78 79 if (out != null) 80 out.flush(); 81 }; 82 } 83 84 public void close() throws java.io.IOException { 85 for (int cntr = 0; cntr < streams.size(); cntr++) { 86 OutputStream out = ((OutputStream )streams.elementAt(cntr)); 87 88 if (out != null) 89 out.close(); 90 }; 91 } 92 93 } 94 | Popular Tags |