code: public static <T> T writeAtomically(final File file, OutputStreamConsumer<T> f) throws IOException
    {
      return writeAtomically(file, file.getParentFile(), f);
    }
docs: Write to a file atomically, by first writing to a temporary file in the same directory and then moving it to
  the target location. This function attempts to clean up its temporary files when possible, but they may stick
  around (for example, if the JVM crashes partway through executing the function). In any case, the target file
  should be unharmed.
  
  The OutputStream passed to the consumer is uncloseable; calling close on it will do nothing. This is to ensure
  that the stream stays open so we can fsync it here before closing. Hopefully, this doesn't cause any problems
  for callers.
  
  This method is not just thread-safe, but is also safe to use from multiple processes on the same machine.