Location tempLocation = configLocation.getTempFile("tmp");
try {
CharStreams.write(GSON.toJson(config), CharStreams.newWriterSupplier(
Locations.newOutputSupplier(tempLocation), Charsets.UTF_8));
Preconditions.checkState(tempLocation.renameTo(configLocation) != null,
"Rename {} to {} failed", tempLocation, configLocation);
} finally {
if (tempLocation.exists()) {
tempLocation.delete();
}