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

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

Introduction

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

Prototype

@Override
    public final void clear() 

Source Link

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 .  java2  s . 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();
}