Example usage for org.apache.commons.configuration2 PropertiesConfiguration getLayout

List of usage examples for org.apache.commons.configuration2 PropertiesConfiguration getLayout

Introduction

In this page you can find the example usage for org.apache.commons.configuration2 PropertiesConfiguration getLayout.

Prototype

public PropertiesConfigurationLayout getLayout() 

Source Link

Document

Returns the associated layout object.

Usage

From source file:com.wavemaker.commons.properties.PropertiesWriter.java

/**
 * This api use apache commons property configuration to persist properties into file
 * and this api will avoid writing current date as comment into property file.
 *
 * @param os/*from  w  w  w.java  2s  .  c  om*/
 */
protected void storeSansDate(OutputStream os) {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.getLayout().setGlobalSeparator("=");
    Enumeration enumeration = properties.keys();
    boolean canComment = true;
    while (enumeration.hasMoreElements()) {
        String key = (String) enumeration.nextElement();
        if (canComment && StringUtils.isNotBlank(comments)) {
            configuration.getLayout().setComment(key, comments);
            canComment = false;
        }
        configuration.setProperty(key, properties.get(key));
    }
    try {
        configuration.getLayout().save(configuration, new OutputStreamWriter(os));

    } catch (ConfigurationException e) {
        throw new WMRuntimeException("Unable to write properties to output stream", e);
    } finally {
        IOUtils.closeSilently(os);
    }
    configuration.clear();
}