@Override
public synchronized int read(byte[] b, int off, int len) throws IOException {
if (b == null)
throw new NullPointerException();
if (off < 0 || len < 0 || len > b.length - off)
throw new IndexOutOfBoundsException();
if (eom)
return -1;
if (len == 0)
return 0;
if (read() == -1)
return -1;
int rlen = Math.min(count - pos, len-1);
int remaining = remaining(pos + rlen);
if (remaining == -1) {
System.arraycopy(buf, pos-1, b, off, rlen+1);
pos += rlen;
return rlen+1;
}
System.arraycopy(buf, pos-1, b, off, remaining+1);
pos += remaining+1;
eom();
return remaining + 1;
}