protected void writeContent(AsyncWritableChannel writeChannel, ReadIntoCallbackWrapper callbackWrapper,
      HttpContent httpContent) {
    ByteBuffer[] contentBuffers;
    // LastHttpContent in the end marker in netty http world.
    boolean isLast = httpContent instanceof LastHttpContent;
    if (isLast) {
      setAutoRead(true);
    }
    if (httpContent.content().nioBufferCount() > 0) {
      contentBuffers = httpContent.content().nioBuffers();
    } else {
      // this will not happen (looking at current implementations of ByteBuf in Netty), but if it does, we cannot avoid
      // a copy (or we can introduce a read(GatheringByteChannel) method in ReadableStreamChannel if required).
      nettyMetrics.contentCopyCount.inc();
      ByteBuf content = httpContent.content();
      logger.warn("HttpContent had to be copied because ByteBuf did not have a backing ByteBuffer");
      ByteBuffer contentBuffer = ByteBuffer.allocate(content.readableBytes());
      // don't change the readerIndex
      content.getBytes(content.readerIndex(), contentBuffer);
      contentBuffer.flip();
      contentBuffers = new ByteBuffer[]{contentBuffer};
    }
    if (digest != null) {
      for (int i = 0; i < contentBuffers.length; i++) {
        long startTime = System.currentTimeMillis();
        digest.update(contentBuffers[i]);
        digestCalculationTimeInMs += (System.currentTimeMillis() - startTime);
      }
    }
    // Retain this httpContent so it won't be garbage collected right away. Release it in the callback.
    httpContent.retain();
    writeChannel.write(httpContent.content(), new ContentWriteCallback(httpContent, isLast, callbackWrapper));
    allContentReceived = isLast;
  }
Writes the data in the provided {@code httpContent} to the given {@code writeChannel}.
@param writeChannel the {@link AsyncWritableChannel} to write the data of {@code httpContent} to.
@param callbackWrapper the {@link ReadIntoCallbackWrapper} for the read operation.
@param httpContent the piece of {@link HttpContent} that needs to be written to the {@code writeChannel}.
ambry-rest/src/main/java/com/github/ambry/rest/NettyRequest.java