added Stream.appendStream()
authoradam <adam@megacz.com>
Mon, 21 Feb 2005 09:24:52 +0000 (09:24 +0000)
committeradam <adam@megacz.com>
Mon, 21 Feb 2005 09:24:52 +0000 (09:24 +0000)
darcs-hash:20050221092452-5007d-bf171cbf4f6140a9298f1ea131e4d8874339a28f.gz

src/org/ibex/io/Stream.java

index f1869d1..c1a1424 100644 (file)
@@ -17,8 +17,13 @@ public class Stream {
     protected final Out out;
     private         StringBuffer log = loggingEnabled ? new StringBuffer(16 * 1024) : null;
     private         String newLine = "\r\n";
     protected final Out out;
     private         StringBuffer log = loggingEnabled ? new StringBuffer(16 * 1024) : null;
     private         String newLine = "\r\n";
+    private   Stream in_next = null;
 
 
-    public static boolean loggingEnabled = System.getProperty("ibex.io.stream.logEnabled", "true") != null;
+    public Stream appendStream(Stream in_next) {
+        if (this.in_next != null) return this.in_next.appendStream(in_next);
+        this.in_next = in_next;
+        return this;
+    }
 
     public  Stream(InputStream in)                   { this.in = new Stream.In(in); this.out = null; }
     public  Stream(                OutputStream out) { this.in = null;              this.out = new Stream.Out(out); }
 
     public  Stream(InputStream in)                   { this.in = new Stream.In(in); this.out = null; }
     public  Stream(                OutputStream out) { this.in = null;              this.out = new Stream.Out(out); }
@@ -139,9 +144,9 @@ public class Stream {
         public void write(String s) { try { w.write(s); } catch (IOException e) { ioe(e); } }
     }
 
         public void write(String s) { try { w.write(s); } catch (IOException e) { ioe(e); } }
     }
 
-    private static class In extends InputStream {
-        public Reader reader = new InputStreamReader(this);
-        private final InputStream orig;
+    private class In extends InputStream {
+        public final Reader reader = new InputStreamReader(this);
+        private /*final*/ InputStream orig;
         public In(InputStream in) { orig = in; }
 
         char[] cbuf = new char[8192];
         public In(InputStream in) { orig = in; }
 
         char[] cbuf = new char[8192];
@@ -161,7 +166,14 @@ public class Stream {
             if (cstart == cend) {
                 cstart = 0;
                 cend = reader.read(cbuf, 0, cbuf.length);
             if (cstart == cend) {
                 cstart = 0;
                 cend = reader.read(cbuf, 0, cbuf.length);
-                if (cend == -1) { cend = cstart; throw new EOF(); }
+                if (cend == -1) {
+                    cend = cstart;
+                    if (in_next == null) throw new EOF();
+                    // FIXME: sketchy
+                    orig = in_next.in.orig;
+                    in_next = in_next.in_next;
+                    return getc(peek);
+                }
             }
             return peek ? cbuf[cstart] : cbuf[cstart++];
         } catch (IOException e) { return (char)ioe(e); } }
             }
             return peek ? cbuf[cstart] : cbuf[cstart++];
         } catch (IOException e) { return (char)ioe(e); } }