class PolicyUpdater {

    static void writePolicies(PolicyUpdaterConfiguration configuration, String domain,
            DomainSignedPolicyData domainSignedPolicyData) throws IOException {

        if (configuration == null) {
            throw new IllegalArgumentException("null configuration");
        }
        String policyTmpDir = configuration.getPolicyFileTmpDir();
        String policyDir    = configuration.getPolicyFileDir();
        if (policyTmpDir == null || policyDir == null || domain == null || domainSignedPolicyData == null) {
            throw new IllegalArgumentException("null parameters are not valid arguments");
        }
        
        String pathToTempFile   = policyTmpDir + File.separator + domain + TEMP_FILE_EXTENSION;
        String pathToPolicyFile = policyDir + File.separator + domain + POLICY_FILE_EXTENSION;

        // ensure tmp dir exists
        verifyTmpDirSetup(configuration);

        LOG.info("Writing temp policy file: " + pathToTempFile);
        // Make a file object from the path name
        File file = new File(pathToTempFile);
        file.createNewFile();
        Files.write(file.toPath(), JSON.bytes(domainSignedPolicyData));

        Path sourceFile = Paths.get(pathToTempFile);
        Path destinationFile = Paths.get(pathToPolicyFile);
        try {
            LOG.info("Moving temp file : " + sourceFile + " to destination: " + destinationFile);
            Files.copy(sourceFile, destinationFile, StandardCopyOption.REPLACE_EXISTING);
            Files.deleteIfExists(sourceFile);
        } catch (IOException exc) {
            LOG.error("PolicyUpdater: Moving temp file failure. source: " + sourceFile
                    + " : destination: " + destinationFile + " : exc: " + exc);
        }
    }

}