private int readBytesFromReadableByteChannel(ReadableByteChannel channel, ByteBuf buffer) throws IOException {
    int n = channel.read(buffer.nioBuffer(buffer.writerIndex(), buffer.capacity() - buffer.writerIndex()));
    if (n > 0) {
      buffer.writerIndex(buffer.writerIndex() + n);
    }
    return n;
  }
Reading bytes from the {@link ReadableByteChannel} and writing those bytes to the given {@link ByteBuf}.
This method would change the writerIndex of the given buffer.
@param channel The {@link ReadableByteChannel} to read the bytes out.
@param buffer The {@link ByteBuf} to write bytes to.
@return The number of bytes read from channel.
@throws IOException Any I/O error.
ambry-api/src/main/java/com/github/ambry/network/BoundedNettyByteBufReceive.java