sclass ByteArraysPartialInputStream extends InputStream { sclass State { int ofs; MinimalChain chain; *(int *ofs, MinimalChain *chain) {} } bool eof; MinimalChain last = new(null); State state = new(0, last); long absolutePosition; public synchronized int read() throws IOException { while ping (true) { if (state.ofs < l(state.chain)) ret state.chain![state.ofs++]; if (state.chain.next == null) ret -1; state = new State(0, state.chain.next); } } public synchronized void add(byte[] buffer) { last.setNext(new MinimalChain(null)); last.setElement(buffer); last = last.next; } public void addEOF() { eof = true; } public bool isEOF() { ret state.head == last && eof; } @Override public bool markSupported() { true; } @Override public void mark(int readLimit) { mark = position; in.mark(readLimit); } @Override public void reset() throws IOException { if (mark < 0) fail(); position = mark; mark = -1; in.reset(); } toString { ret renderVars SimulatedPartialInputStream(+streamEnded, +position, +cutOffPoint, +mark); } }