private static void createTmpFile(CompletableFuture<NewFile> fileCreation,Path destDir,List<TSData> files){
  LOG.log(Level.FINE,"starting temporary file creation...");
  try {
    Collections.sort(files,Comparator.comparing(null));
    final FileChannel fd=FileUtil.createTempFile(destDir,"monsoon-",".optimize-tmp");
    try {
      final DateTime begin;
      try (ToXdrTables output=new ToXdrTables(fd,Compression.DEFAULT_OPTIMIZED)){
        while (!files.isEmpty()) {
          TSData tsdata=files.remove(0);
          if (fileCreation.isCancelled())           throw new IOException("aborted due to canceled execution");
          output.addAll(tsdata);
        }
        begin=new DateTime(output.getHdrBegin(),DateTimeZone.UTC);
        if (fileCreation.isCancelled())         throw new IOException("aborted due to canceled execution");
      }
       if (fileCreation.isCancelled())       throw new IOException("aborted due to canceled execution");
      INSTALL_POOL.execute(null);
    }
 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);
  }
}

private static void createTmpFile ( CompletableFuture < NewFile > fileCreation , Path destDir , List < TSData > files ) { LOG . log ( Level . FINE , "starting temporary file creation..." ) ; try { Collections . sort ( files , Comparator . comparing ( null ) ) ; final FileChannel fd = FileUtil . createTempFile ( destDir , "monsoon-" , ".optimize-tmp" ) ; try { final DateTime begin ; try ( ToXdrTables output = new ToXdrTables ( fd , Compression . DEFAULT_OPTIMIZED ) ) { while ( ! files . isEmpty ( ) ) { TSData tsdata = files . remove ( 0 ) ; if ( fileCreation . isCancelled ( ) ) throw new IOException ( "aborted due to canceled execution" ) ; output . addAll ( tsdata ) ; } begin = new DateTime ( output . getHdrBegin ( ) , DateTimeZone . UTC ) ; if ( fileCreation . isCancelled ( ) ) throw new IOException ( "aborted due to canceled execution" ) ; } if ( fileCreation . isCancelled ( ) ) throw new IOException ( "aborted due to canceled execution" ) ; INSTALL_POOL . execute ( null ) ; } 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 ) ; } }
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 .
