Search in sources :

Example 1 with ConfigurationEvent

use of org.apache.commons.configuration2.event.ConfigurationEvent in project winery by eclipse.

the class AutoSaveListener method onEvent.

@Override
public void onEvent(ConfigurationEvent event) {
    if (!event.isBeforeUpdate()) {
        try {
            if (!Files.exists(this.path.getParent())) {
                Files.createDirectories(this.path.getParent());
            }
        } catch (IOException ce) {
            LOGGER.error("Could not update properties file", ce);
            return;
        }
        try (OutputStream out = Files.newOutputStream(this.path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
            OutputStreamWriter writer = new OutputStreamWriter(out);
            this.configuration.write(writer);
        } catch (ConfigurationException | IOException ce) {
            LOGGER.error("Could not update properties file", ce);
        }
    }
}
Also used : ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)1