@Override
  public int write(ByteBuffer src) throws ClosedChannelException {
    if (!isOpen()) {
      throw new ClosedChannelException();
    }
    int bytesWritten = 0;
    bufferLock.lock();
    try {
      int bytesToWrite = Math.min(src.remaining(), buffer.remaining());
      for (; bytesWritten < bytesToWrite; bytesWritten++) {
        buffer.put(src.get());
      }
    } finally {
      bufferLock.unlock();
    }
    return bytesWritten;
  }
{@inheritDoc}
<p/>
Copies bytes from {@code src} into the {@link ByteBuffer} ({@code buffer}) backing this channel. The number of
bytes copied is the minimum of {@code src.remaining()} and {@code buffer.remaining()}.
@param src the source {@link ByteBuffer} 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/ByteBufferChannel.java