1 package com.quadcap.io; 2 3 40 41 import java.io.InputStream ; 42 import java.io.IOException ; 43 44 import java.util.Vector ; 45 46 import com.quadcap.util.Debug; 47 48 54 public class ConcatInputStream extends InputStream { 55 Vector streams = new Vector (); 56 int stream = 0; 57 58 65 public ConcatInputStream(InputStream in1, InputStream in2) { 66 streams.addElement(in1); 67 streams.addElement(in2); 68 } 69 70 75 public void addInputStream(InputStream in) { 76 streams.addElement(in); 77 } 78 79 93 public int read() throws IOException { 94 while (stream < streams.size()) { 95 InputStream is = (InputStream )streams.elementAt(stream); 96 int c = is.read(); 97 if (c >= 0) return c; 98 stream++; 99 } 100 return -1; 101 } 102 103 112 public int available() throws IOException { 113 int avail = 0; 114 for (int i = stream; i < streams.size(); i++) { 115 InputStream is = (InputStream )streams.elementAt(i); 116 avail += is.available(); 117 } 118 return avail; 119 } 120 121 } 122 | Popular Tags |