@Override public int read() throws IOException { commitToMode(); if (mode == Mode.SYNCHRONOUS) { return synchronousStream.read(); } validateState(); return doRead(); }
@Override public int read(byte[] b, int off, int len) throws IOException { commitToMode(); if (mode == Mode.SYNCHRONOUS) { return synchronousStream.read(b, off, len); } // some validation borrowed from InputStream if (b == null) { throw new NullPointerException(); } else if (off < 0 || len < 0 || len > b.length - off) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } validateState(); for (int i = 0; i < len; i++) { if (!hasDataToRead()) { return i; } b[off + i] = doRead(); } // if we are here we were able to fill the entire buffer return len; }