@Override
  public int read(byte b[], int off, int len) {
    int avail = available();
    if (avail <= 0) {
      return -1;
    }
    if (len <= 0) {
      return 0;
    }

    if (len > avail) {
      len = avail;
    }
    this.buf.get(b, off, len);
    return len;
  }
Reads up to next <code>len</code> bytes of data from buffer into passed array(starting from
given offset).
@param b   the array into which the data is read.
@param off the start offset in the destination array <code>b</code>
@param len the maximum number of bytes to read.
@return the total number of bytes actually read into the buffer, or <code>-1</code> if not even
        1 byte can be read because the end of the stream has been reached.
hbase-common/src/main/java/org/apache/hadoop/hbase/io/ByteBuffInputStream.java