public static void execute(String fileName,String tmpPrefix,Callback callback,CopyOption... options) throws Exception {
  Path target=Paths.get(fileName);
  Path parentPath=target.getParent();
  Path tempFile=DefaultFilepaths.createTempFile(parentPath,tmpPrefix,null);
  SeekableByteChannel channel=Files.newByteChannel(tempFile,CREATE,WRITE,TRUNCATE_EXISTING,DSYNC);
  try (OutputStream out=Channels.newOutputStream(channel)){
    callback.save(out);
  }
   if (options.length == 0) {
    Files.move(tempFile,target,StandardCopyOption.REPLACE_EXISTING);
  }
 else {
    Files.move(tempFile,target,options);
  }
}

public static void execute ( String fileName , String tmpPrefix , Callback callback , CopyOption ... options ) throws Exception { Path target = Paths . get ( fileName ) ; Path parentPath = target . getParent ( ) ; Path tempFile = DefaultFilepaths . createTempFile ( parentPath , tmpPrefix , null ) ; SeekableByteChannel channel = Files . newByteChannel ( tempFile , CREATE , WRITE , TRUNCATE_EXISTING , DSYNC ) ; try ( OutputStream out = Channels . newOutputStream ( channel ) ) { callback . save ( out ) ; } if ( options . length == 0 ) { Files . move ( tempFile , target , StandardCopyOption . REPLACE_EXISTING ) ; } else { Files . move ( tempFile , target , options ) ; } }
atomically executes the given callback as part of the atomic save to the provided filename . if an error occurs no changes to the file will be made .
