code: private static void createTmpFile(CompletableFuture<NewFile> fileCreation, Path destDir, List<TSData> files, Compression compression) {
          LOG.log(Level.FINE, "starting temporary file creation...");
  
          try {
              Collections.sort(files, Comparator.comparing(TSData::getBegin));
  
              final FileChannel fd = FileUtil.createTempFile(destDir, "monsoon-", ".optimize-tmp");
              try {
                  final DateTime begin;
                  try (ToXdrTables output = new ToXdrTables()) {
                      while (!files.isEmpty()) {
                          TSData tsdata = files.remove(0);
                          if (fileCreation.isCancelled())
                              throw new IOException("aborted due to canceled execution");
                          output.addAll(tsdata);  // Takes a long time.
                      }
  
                      if (fileCreation.isCancelled())
                          throw new IOException("aborted due to canceled execution");
                      begin = output.build(fd, compression); // Writing output takes a lot of time.
                  }
  
                  if (fileCreation.isCancelled()) // Recheck after closing output.
                      throw new IOException("aborted due to canceled execution");
  
                  // Forward the temporary file to the installation, which will complete the operation.
                  INSTALL_POOL.execute(() -> install(fileCreation, destDir, fd, begin));
              } catch (Error | RuntimeException | IOException ex) {
                  try {
                      fd.close();
                  } catch (Error | RuntimeException | IOException ex1) {
                      ex.addSuppressed(ex1);
                  }
                  throw ex;
              }
          } catch (Error | RuntimeException | IOException ex) {
              LOG.log(Level.WARNING, "temporary file for optimization failure", ex);
              synchronized (OUTSTANDING) {
                  OUTSTANDING.remove(fileCreation);
              }
              fileCreation.completeExceptionally(ex);  // Propagate exceptions.
          }
      }
docs: The fork-join task that creates a new file. This function creates a
  temporary file with the result contents, then passes it on to the install
  thread which will put the final file in place.
  
  @param fileCreation the future that is to be completed after the
  operation.
  @param destDir the destination directory for the result; also used for
  temporary file creation.
  @param files the list of files that make up the resulting file.