code: @Nonnull
      private static File writeDataToTempFileOrDie(@Nonnull final OutputStreamCallback callback,
                                                   @Nonnull final File targetFile,
                                                   @Nonnull final Logger log) throws IOException {
          Preconditions.checkNotNull(callback, "callback argument is required!");
          Preconditions.checkNotNull(log, "log argument is required!");
          Preconditions.checkNotNull(targetFile, "targetFile argument is required!");
  
          FileOutputStream fileOut = null;
          FileChannel fileChannel = null;
          try {
              final String targetFinalName = targetFile.getName();
              final File targetDirectory = targetFile.getParentFile();
  
              // open temporary file
              final File tmpFile = File.createTempFile(targetFinalName, ".tmp", targetDirectory);
  
              fileOut = new FileOutputStream(tmpFile);
              fileChannel = fileOut.getChannel();
  
              // make sure to use an output stream that flows THROUGH the FileChannel, so that FileChannel.force(true)
              // can do what it's supposed to
  
              // write the data AND flush it
              callback.writeAndFlushData(Channels.newOutputStream(fileChannel));
  
              return tmpFile;
          } finally {
              try {
                  // fsync to disk (both data AND length)
                  if (fileChannel != null) {
                      fileChannel.force(true);
                  }
              } finally {
                  // close the open file (if during an EXC,
                  if (fileOut != null) {
                      fileOut.close();
                  }
              }
          }
      }
docs: return a reference to a temp file that contains the written + flushed + fsynced + closed data