List of usage examples for org.apache.commons.configuration PropertiesConfiguration load
public void load(InputStream in, String encoding) throws ConfigurationException
From source file:com.github.anba.es6draft.util.Resources.java
/** * Loads the configuration file./*from w w w . java 2 s .co m*/ */ public static Configuration loadConfiguration(Class<?> clazz) { TestConfiguration config = clazz.getAnnotation(TestConfiguration.class); String file = config.file(); String name = config.name(); try { PropertiesConfiguration properties = new PropertiesConfiguration(); // entries are mandatory unless an explicit default value was given properties.setThrowExceptionOnMissing(true); properties.getInterpolator().setParentInterpolator(MISSING_VAR); properties.load(resource(file), "UTF-8"); Configuration configuration = new CompositeConfiguration( Arrays.asList(new SystemConfiguration(), properties)); return configuration.subset(name); } catch (ConfigurationException | IOException e) { throw new RuntimeException(e); } catch (NoSuchElementException e) { throw e; } }
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 {/*from w ww . j av a 2s . com*/ 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); } }