title: How to read and write files in a reactive way using InputStreamand OutputStream
body: <p>I am trying to read an Excel file in manipulate it or add new data to it and write it back out. I am also trying to do this a complete reactive process using Flux and Mono. The Idea is to return the resulting file or bytearray via a webservice.</p>
  
  <p>My question is how do I get a InputStream and OutputStream in a non blocking way? </p>
  
  <p>I am using the Apache Poi library to read and generate the Excel File.</p>
  
  <p>I currently have a solution based around a mix of Mono.fromCallable() and Blocking code getting the Input Stream.</p>
  
  <p>For example the webservice part is as follows.</p>
  
  <pre><code>@GetMapping(value = API_BASE_PATH + "/download", produces = "application/vnd.ms-excel")
  public Mono&lt;ByteArrayResource&gt; download() {
      Flux&lt;TimeKeepingEntry&gt; createExcel = excelExport.createDocument(false);
  
      return createExcel.then(Mono.fromCallable(() -&gt; {
          ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
          excelExport.getWb().write(outputStream);
          return new ByteArrayResource(outputStream.toByteArray());
      }).subscribeOn(Schedulers.elastic()));
  }
  </code></pre>
  
  <p>And the Processing of the file:</p>
  
  <pre><code>public Flux&lt;TimeKeepingEntry&gt; createDocument(boolean all) {
      Flux&lt;TimeKeepingEntry&gt; entries = null;
      try {
          InputStream inputStream = new ClassPathResource("Timesheet Template.xlsx").getInputStream();
          wb = WorkbookFactory.create(inputStream);
          Sheet sheet = wb.getSheetAt(0);
  
          log.info("Created document");
  
          if (all) {
              //all entries
          } else {
              entries = service.findByMonth(currentMonthName).log("Excel Export - retrievedMonths").sort(Comparator.comparing(TimeKeepingEntry::getDateOfMonth)).doOnNext(timeKeepingEntry-&gt; {
                  this.populateEntry(sheet, timeKeepingEntry);
              });
          }
      } catch (IOException e) {
          log.error("Error Importing File", e);
      }
      return entries;
  }
  </code></pre>
  
  <p>This works well enough but not very in line with Flux and Mono. Some guidance here would be good. I would prefer to have the whole sequence non-blocking.</p>