@Override
  public int write(ByteBuffer src) throws ClosedChannelException {
    if (!isOpen()) {
      throw new ClosedChannelException();
    }
    int size = src.remaining();
    ByteBuf copy = src.isDirect() ? ByteBufAllocator.DEFAULT.directBuffer(src.remaining())
        : PooledByteBufAllocator.DEFAULT.heapBuffer(src.remaining());
    copy.writeBytes(src);
    compositeBuffer.addComponent(true, copy);
    src.position(src.limit());
    return size;
  }
Copies bytes from {@code src} into the composite buf.
@param src the source {@link ByteBuf} to copy bytes from.
@return the number of bytes copied.
@throws ClosedChannelException if the channel is closed when this function was called.
ambry-utils/src/main/java/com/github/ambry/utils/ByteBufChannel.java