@Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
@Override public int available() throws IOException { return inBuf() + src.available(); }
private void fillBuf() throws IOException { if (readPos == writePos) { readPos = 0; writePos = 0; } if (readPos * 3 > CAPACITY) { int had = inBuf(); System.arraycopy(buf, readPos, buf, 0, had); readPos = 0; writePos = had; } int wantToRead = CAPACITY - writePos; if (inBuf() > 0) { // if we have data already, do not block, read only what is available wantToRead = Math.min(wantToRead, src.available()); } if (wantToRead > 0) { int got = src.read(buf, writePos, wantToRead); if (got > 0) { dst.write(buf, writePos, got); writePos += got; } } }