if (throwExceptionOnNextUse) {
throw new IOException("Exception thrown for testing purpose.");
}
int available = len - pos;
if (available > 0) {
int readable = (available < count ? available : count);
System.arraycopy(buf, pos, dest, offset, readable);
pos += readable;
return readable;
} else {
return -1;
}