@Override public int read(final char[] cbuf, final int off, final int len) throws IOException { if ((off | len | off + len | cbuf.length - (off + len)) < 0) { throw new IndexOutOfBoundsException(); } if (len == 0) { checkNotClosed(); return 0; } final int available = this.count - this.pos; if (available == 0) { fill(); if (this.count == 0) { return -1; } } final int n = available > len ? len : available; System.arraycopy(this.buffer, this.pos, cbuf, off, n); this.pos += n; return n; }
@Override public long skip(final long n) throws IOException { if (n <= 0) { checkNotClosed(); return 0; } int available = this.count - this.pos; if (available == 0) { fill(); available = this.count; } final long skipped = available < n ? available : n; this.pos += skipped; return skipped; }
private void fill() throws IOException { checkNotClosed(); if (this.buffer != null) { this.buffer = null; this.pos = 0; this.count = 0; } if (this.index == this.buffers.size()) { this.fetcher.fetch(this.buffers); this.index = 0; } if (this.index < this.buffers.size()) { final CharBuffer cb = this.buffers.get(this.index++); this.buffer = cb.array(); this.count = cb.limit(); } }
public static Reader parallelBuffer(final Reader reader, final char delimiter) { return new ParallelBufferedReader(reader, delimiter); }
@Override public int read() throws IOException { if (this.pos >= this.count) { fill(); if (this.count == 0) { return -1; } } return this.buffer[this.pos++] & 0xFFFF; }