code: public static void writeAtomically(File file, byte[] bytes) throws IOException {
  		AtomicFile atomicFile = new AtomicFile(file);
  		FileOutputStream stream = null;
  		try {
  			stream = atomicFile.startWrite();
  			stream.write(bytes);
  			atomicFile.finishWrite(stream); // serialization was successful
  		} catch (Exception e) {
  			atomicFile.failWrite(stream); // serialization failed
  			throw new IOException(e); // throw exception up the chain
  		}
  	}
docs: Performs an 'atomic' write to a file (to avoid data corruption)