X-Git-Url: http://git.megacz.com/?p=org.ibex.io.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fio%2FByteBufInputStream.java;h=bede9d2b5b88836b83a5668116940b75abe55a5a;hp=7581c88276e47d1cf7a02ebc4fddc0214a604ab2;hb=073dfe2f5f0338b98567400881dbc4244632e054;hpb=3e1c83f8d1d65b96a3e24c3aa2a042c21f005111 diff --git a/src/org/ibex/io/ByteBufInputStream.java b/src/org/ibex/io/ByteBufInputStream.java index 7581c88..bede9d2 100644 --- a/src/org/ibex/io/ByteBufInputStream.java +++ b/src/org/ibex/io/ByteBufInputStream.java @@ -9,7 +9,7 @@ import java.io.*; abstract class ByteBufInputStream extends InputStream { private InputStream is; - public InputStream next; + public Stream next = null; private byte[] buf = new byte[8192]; private int start = 0; private int end = 0; @@ -18,17 +18,29 @@ abstract class ByteBufInputStream extends InputStream { this.is = is; } + public void appendStream(Stream next) { + if (this.next == null) this.next = next; + else this.next.appendStream(next); + } private int bufSize() { if (end==start) { end = start = 0; } return end-start; } private int fillBufIfEmpty() { try { if (bufSize() > 0) return bufSize(); + if (is == null) return -1; + if (prereading) return -1; start = 0; do { end = is.read(buf, 0, buf.length); - if (end == -1 && next != null) { + if (end == -1) { is.close(); - is = next; - continue; + is = null; + if (next != null) { + // FIXME: append to a stream that has already run out? + is = next.getInputStream(); + next = null; + start = end = 0; + continue; + } } } while(end==0); if (end == -1) { end = 0; return -1; }