// XXX: any way to make this automatically free? @Override public int read(byte[] buf, int offset, int length) throws IOException { TempBuffer cursor = _cursor; if (cursor == null) return -1; int sublen = cursor._length - _offset; if (length < sublen) sublen = length; System.arraycopy(cursor._buf, _offset, buf, offset, sublen); if (cursor._length <= _offset + sublen) { _cursor = cursor._next; if (_freeWhenDone) { cursor._next = null; TempBuffer.free(cursor); cursor = null; } _offset = 0; } else _offset += sublen; return sublen; }
@Override public void close() throws IOException { if (_freeWhenDone && _cursor != null) TempBuffer.freeAll(_cursor); _cursor = null; }