-// Copyright 2004 Adam Megacz, see the COPYING file for licensing [LGPL]
+// Copyright 2000-2005 the Contributors, as shown in the revision logs.
+// Licensed under the Apache Public Source License 2.0 ("the License").
+// You may not use this file except in compliance with the License.
+
package org.ibex.io;
import java.io.*;
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 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];
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); } }
} finally { flushing = false; }
}
- Writer unreader = new OutputStreamWriter(new OutputStream() {
- public void close() { }
- public void write(int i) throws IOException { byte[] b = new byte[1]; b[0] = (byte)i; write(b, 0, 1); }
- public void write(byte[] b) throws IOException { write(b, 0, b.length); }
- public void write(byte[] b, int p, int l) {
- ensureb2(l);
- System.arraycopy(b, p, buf, start-l, l);
- start -= l;
- }
- });
+ Writer unreader = new OutputStreamWriter(new InOutputStream());
+ private class InOutputStream extends OutputStream {
+ public void close() { }
+ public void write(int i) throws IOException { byte[] b = new byte[1]; b[0] = (byte)i; write(b, 0, 1); }
+ public void write(byte[] b) throws IOException { write(b, 0, b.length); }
+ public void write(byte[] b, int p, int l) {
+ ensureb2(l);
+ System.arraycopy(b, p, buf, start-l, l);
+ start -= l;
+ }
+ }
}
}