code: private static void streamResource(ServiceRequestContext ctx, HttpResponseWriter res,
                                         ReadableByteChannel in, long remainingBytes) {
  
          final int chunkSize = (int) Math.min(8192, remainingBytes);
          final ByteBuf buf = ctx.alloc().buffer(chunkSize);
          final int readBytes;
          boolean success = false;
          try {
              readBytes = read(in, buf);
              if (readBytes < 0) {
                  // Should not reach here because we only read up to the end of the stream.
                  // If reached, it may mean the stream has been truncated.
                  throw new EOFException();
              }
              success = true;
          } catch (Exception e) {
              close(res, in, e);
              return;
          } finally {
              if (!success) {
                  buf.release();
              }
          }
  
          final long nextRemainingBytes = remainingBytes - readBytes;
          final boolean endOfStream = nextRemainingBytes == 0;
          if (readBytes > 0) {
              if (!res.tryWrite(new ByteBufHttpData(buf, endOfStream))) {
                  close(in);
                  return;
              }
          } else {
              buf.release();
          }
  
          if (endOfStream) {
              close(res, in);
              return;
          }
  
          res.onDemand(() -> {
              try {
                  ctx.blockingTaskExecutor().execute(() -> streamResource(ctx, res, in, nextRemainingBytes));
              } catch (Exception e) {
                  close(res, in, e);
              }
          });
      }
docs: streaming a ReadableByteChannel and an InputStream.