@Override
  public int read(byte[] bytes, int offset, int length) throws IOException {
    if (bytes == null) {
      throw new NullPointerException();
    } else if (offset < 0 || length < 0 || length > bytes.length - offset) {
      throw new IndexOutOfBoundsException();
    } else if (length == 0) {
      return 0;
    }
    int count = Math.min(byteBuffer.remaining(), length);
    if (count == 0) {
      return -1;
    }
    byteBuffer.get(bytes, offset, count);
    return count;
  }
Reads 'size' amount of bytes from the stream into the buffer.
@param stream The stream from which bytes need to be read. If the underlying stream is SocketInputStream, it needs
              to be blocking.
@param size The size that needs to be read from the stream
@throws IOException
ambry-utils/src/main/java/com/github/ambry/utils/ByteBufferInputStream.java