Example usage for org.apache.commons.configuration PropertiesConfiguration save

List of usage examples for org.apache.commons.configuration PropertiesConfiguration save

Introduction

In this page you can find the example usage for org.apache.commons.configuration PropertiesConfiguration save.

Prototype

public void save(OutputStream out, String encoding) throws ConfigurationException 

Source Link

Document

Save the configuration to the specified stream, using the specified encoding.

Usage

From source file:com.github.zdsiyan.maven.plugin.smartconfig.internal.PropertyConfigurator.java

@Override
public ByteArrayOutputStream execute(InputStream in, Charset charset, List<PointHandle> pointhandles)
        throws IOException {
    try {/* ww  w  . j a v a 2s  . co m*/
        PropertiesConfiguration configuration = new PropertiesConfiguration();
        configuration.load(in, charset.name());

        pointhandles.forEach(point -> {
            switch (point.getMode()) {
            case insert:
                configuration.addProperty(point.getExpression(), point.getValue());
                break;
            case delete:
                configuration.setProperty(point.getExpression(), "");
                break;
            case replace:
            default:
                configuration.setProperty(point.getExpression(), point.getValue());
                break;
            }
        });

        // output
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        configuration.save(out, charset.name());
        return out;
    } catch (ConfigurationException ex) {
        // FIXME
        throw new RuntimeException(ex);
    }
}