Example usage for org.apache.commons.configuration2.builder FileBasedConfigurationBuilder save

List of usage examples for org.apache.commons.configuration2.builder FileBasedConfigurationBuilder save

Introduction

In this page you can find the example usage for org.apache.commons.configuration2.builder FileBasedConfigurationBuilder save.

Prototype

public void save() throws ConfigurationException 

Source Link

Document

Convenience method which saves the associated configuration.

Usage

From source file:org.talend.dataprep.encrypt.PropertiesEncryption.java

/**
 * Applies the specified function to the specified set of parameters contained in the input file.
 *
 * @param input The specified name of file to encrypt
 * @param mustBeModified the specified set of parameters
 * @param function the specified function to apply to the set of specified parameters
 *//*from  ww w  . ja v a  2  s.  c o  m*/
private void modifyAndSave(String input, Set<String> mustBeModified, Function<String, String> function) {
    Path inputFilePath = Paths.get(input);
    if (Files.exists(inputFilePath) && Files.isRegularFile(inputFilePath) && Files.isReadable(inputFilePath)) {
        try {
            Parameters params = new Parameters();
            FileBasedConfigurationBuilder<PropertiesConfiguration> builder = //
                    new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class) //
                            .configure(params.fileBased() //
                                    .setFile(inputFilePath.toFile())); //
            PropertiesConfiguration config = builder.getConfiguration();
            for (String key : mustBeModified) {
                config.setProperty(key, function.apply(config.getString(key)));
            }
            builder.save();
        } catch (ConfigurationException e) {
            LOGGER.error("unable to read {} {}", input, e);
        }
    } else {
        LOGGER.debug("No readable file at {}", input);
    }
}