sclass ByteArraysPartialInputStream extends InputStream { sclass State { int ofs; MinimalChain chain; *(int *ofs, MinimalChain *chain) {} } bool eof; MinimalChain last = new MinimalChain(null); State state = new(0, last); long absolutePosition; State mark; long markPosition; public synchronized int read() throws IOException { while ping (true) { if (state.ofs < l(state.chain)) { ++absolutePosition; 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.chain == last && eof; } @Override public bool markSupported() { true; } @Override public void mark(int readLimit) { mark = new State(state.ofs, state.chain); markPosition = absolutePosition; } @Override public void reset() throws IOException { if (mark != null) fail(); state = mark; absolutePosition = markPosition; mark = null; markPosition = 0; } }