title: Downlolad and save file from ClientRequest using ExchangeFunction in Project Reactor
body: <p>I have problem with correctly saving a file after its download is complete in Project Reactor.</p>
  
  <pre><code>class HttpImageClientDownloader implements ImageClientDownloader {
  
      private final ExchangeFunction exchangeFunction;
  
      HttpImageClientDownloader() {
          this.exchangeFunction = ExchangeFunctions.create(new ReactorClientHttpConnector());
      }
  
      @Override
      public Mono&lt;File&gt; downloadImage(String url, Path destination) {
  
          ClientRequest clientRequest = ClientRequest.create(HttpMethod.GET, URI.create(url)).build();
          return exchangeFunction.exchange(clientRequest)
                  .map(clientResponse -&gt; clientResponse.body(BodyExtractors.toDataBuffers()))
                  //.flatMapMany(clientResponse -&gt; clientResponse.body(BodyExtractors.toDataBuffers()))
                  .flatMap(dataBuffer -&gt; {
  
                      AsynchronousFileChannel fileChannel = createFile(destination);
                      return DataBufferUtils
                              .write(dataBuffer, fileChannel, 0)
                              .publishOn(Schedulers.elastic())
                              .doOnNext(DataBufferUtils::release)
                              .then(Mono.just(destination.toFile()));
  
  
                  });
  
      }
  
      private AsynchronousFileChannel createFile(Path path) {
          try {
              return AsynchronousFileChannel.open(path, StandardOpenOption.CREATE);
          } catch (Exception e) {
              throw new ImageDownloadException("Error while creating file: " + path, e);
          }
      }
  }
  </code></pre>
  
  <p>So my question is:
  Is DataBufferUtils.write(dataBuffer, fileChannel, 0) blocking? </p>
  
  <p>What about when the disk is slow?</p>
  
  <p>And second question about what happens when ImageDownloadException occurs , 
   In doOnNext I want to release the given data buffer, is that a good place for this kind operation?</p>
  
  <p>I think also this line:</p>
  
  <blockquote>
  <pre><code>            .map(clientResponse -&gt; clientResponse.body(BodyExtractors.toDataBuffers()))
  </code></pre>
  </blockquote>
  
  <p>could be blocking...</p>