code: public static void writeObjectToFileOrDie(@Nonnull final Object obj, @Nonnull final String file, @Nonnull final Logger log) throws IOException {
          Preconditions.checkNotNull(file, "file argument is required!");
          Preconditions.checkArgument(!file.isEmpty(), "file argument is required!");
  
          // todo: should 'obj' be required? do we ever WANT to write 'null' to an artifact?
          Preconditions.checkNotNull(obj, "cannot write a 'null' object");
  
          final File targetFile = new File(file);
  
          // write object to temporary file that is flushed, fsynced, and closed by the time it returns
          final ObjectOutputStreamCallback callback = new ObjectOutputStreamCallback(obj);
          final File tmpFile = writeDataToTempFileOrDie(callback, targetFile, log);
          final long checksumForWrittenData = callback.getChecksumValue();
  
          // verify that what we WROTE to the disk is then immediately READABLE before allowing the rename to happen
          final long checksumFound = computeFileChecksum(tmpFile, new CRC32());
          if (checksumForWrittenData != checksumFound) {
              throw new IOException("Data written to file is not what we expected, " + checksumFound + " != " + checksumForWrittenData + ": " + tmpFile);
          }
  
          if (!tmpFile.renameTo(targetFile)) {
              // failed to atomically rename from temp file to target file, so throw an exception, leaving the filesystem in
              // a sane state at all times
              throw new IOException("Could not rename '" + tmpFile + "' to '" + targetFile + "'.");
          }
      }
docs: Serializes an object to a file, throws an exception if it fails
  
  @param obj object to write to a file
  @param file path to save the object to
  @param log logger to use
  @throws java.io.IOException if the existing file could not be erased, or the file could not be written, flushed, synced, or closed