@Override
  public int read(byte[] buffer, int offset, int length) {
    if (offset < 0 || length < 0 || offset + length > buffer.length) {
      throw new ArrayIndexOutOfBoundsException(
          "length=" + buffer.length + "; regionStart=" + offset + "; regionLength=" + length);
    }

    final int available = available();
    if (available <= 0) {
      return -1;
    }

    if (length <= 0) {
      return 0;
    }

    int numToRead = Math.min(available, length);
    mPooledByteBuffer.read(mOffset, buffer, offset, numToRead);
    mOffset += numToRead;
    return numToRead;
  }
Reads at most {@code length} bytes from this stream and stores them in byte array {@code
buffer} starting at {@code offset}.

@param buffer the buffer to read data into
@param offset start offset in the buffer
@param length max number of bytes to read
@return number of bytes read
fbcore/src/main/java/com/facebook/common/memory/PooledByteBufferInputStream.java