private void writeToChannel() {
    if (channelWriteException == null && streamed < streamSize) {
      if (!isOpen()) {
        invokeCallback(streamed, new ClosedChannelException());
      } else {
        int bytesLeft = streamSize - streamed > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) (streamSize - streamed);
        bytes.rewind();
        bytes.limit(Math.min(bytes.capacity(), bytesLeft));
        writeChannel.write(bytes, new Callback<Long>() {
          @Override
          public void onCompletion(Long result, Exception callbackException) {
            streamed += result;
            channelWriteException = callbackException;
            writeToChannel();
          }
        });
      }
    } else {
      invokeCallback(streamed, channelWriteException);
    }
  }
Writes continuously to the provided {@link AsyncWritableChannel} until {@link #streamSize} is reached.
ambry-tools/src/main/java/com/github/ambry/tools/perf/rest/PerfRSC.java