1 23 package net.sf.packtag.util; 24 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 28 29 30 36 public class CombinedInputStream extends InputStream { 37 38 39 private int current; 40 41 42 private InputStream [] streams; 43 44 45 50 public CombinedInputStream(InputStream [] streams) { 51 current = 0; 52 this.streams = streams; 53 } 54 55 56 59 public int read() throws IOException { 60 int i = -1; 61 if (current < streams.length) { 62 i = streams[current].read(); 63 if (i == -1) { 64 current++; 66 return read(); 67 } 68 } 69 return i; 70 } 71 72 73 74 public void close() throws IOException { 75 for (int i = 0; i < streams.length; i++) { 76 streams[i].close(); 77 } 78 } 79 80 81 82 public int available() throws IOException { 83 return current < streams.length ? streams[current].available() : 0; 84 } 85 } 86 | Popular Tags |