@Override public int read(byte[] b, int off, int len) throws IOException { return is.read(b, off, len); }
@Override public int read(byte[] b, int off, int len) throws IOException { return is.read(b, off, len); }
/** * Fills the internal buffer by reading from the given input stream. * * @param input input stream to read from * @param size number of bytes to read * @throws IOException if failed to read from the stream * @throws EOFException if failed to read the given number of bytes from the input */ void fillBuffer(SeekableInputStream input, int size) throws IOException { buffer.clear(); buffer = ensureCapacity(buffer, size); try { basePosition = input.getPos(); int bytesRead = 0; while (bytesRead != size) { int len = input.read(buffer.array(), bytesRead, size - bytesRead); if (len < 0) { throw new EOFException("Expected to read " + size + ", but only " + bytesRead + " was read"); } bytesRead += len; } buffer.limit(size); bufferInput.reset(buffer); } catch (IOException e) { // Make the buffer has nothing to read buffer.position(buffer.limit()); basePosition = -1L; throw e; } }