private boolean saveProperties() {
        if (file == null) {
            Log.error("Unable to save XML properties", new IllegalStateException("No file specified"));
            return false;
        }

        // Write data out to a temporary file first.
        final Path tempFile = file.getParent().resolve(file.getFileName() + ".tmp");
        try (final Writer writer = Files.newBufferedWriter(tempFile, StandardCharsets.UTF_8)) {
            OutputFormat prettyPrinter = OutputFormat.createPrettyPrint();
            XMLWriter xmlWriter = new XMLWriter(writer, prettyPrinter);
            xmlWriter.write(document);
        } catch (final Exception e) {
            Log.error("Unable to write properties to tmpFile {}", tempFile, e);
            // There were errors so abort replacing the old property file.
            return false;
        }

        // No errors occurred, so replace the main file.
        try {
            Files.move(tempFile, file, StandardCopyOption.REPLACE_EXISTING);
        } catch (final Exception e) {
            Log.error("Error moving new property file from {} to {}:", tempFile, file, e);
            return false;
        }

        return true;
    }
Saves the properties to disk as an XML document. A temporary file is
used during the writing process for maximum safety.

Callers <em>MUST</em> hold the write-lock from {@link #readWriteLock}.

@return false if the file could not be saved, otherwise true
xmppserver/src/main/java/org/jivesoftware/util/XMLProperties.java