private void writeToChannel(final AsyncWritableChannel writableChannel) {
    executorService.submit(new Runnable() {
      @Override
      public void run() {
        try {
          byte[] buffer = new byte[(int) bufferSize];
          final int read = fillBuffer(buffer);
          if (read > 0) {
            ByteBuffer bufferToWrite = ByteBuffer.wrap(buffer);
            bufferToWrite.limit(read);
            writableChannel.write(bufferToWrite, new Callback<Long>() {
              @Override
              public void onCompletion(Long result, Exception exception) {
                if (exception != null) {
                  callbackWrapper.invokeCallback(exception);
                } else {
                  callbackWrapper.updateBytesRead(result);
                  writeToChannel(writableChannel);
                }
              }
            });
          } else {
            // the input stream has been emptied.
            callbackWrapper.invokeCallback(null);
          }
        } catch (Exception e) {
          callbackWrapper.invokeCallback(e);
        }
      }
    });
  }
Reads data from the {@link InputStream} asynchronously and writes it to the given {@code writableChannel}
@param writableChannel the {@link AsyncWritableChannel} into which data from the {@link InputStream}is written.
ambry-commons/src/main/java/com/github/ambry/commons/InputStreamReadableStreamChannel.java