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

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

Introduction

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

Prototype

public PropertiesConfiguration() 

Source Link

Document

Creates an empty PropertyConfiguration object which can be used to synthesize a new Properties file by adding values and then saving().

Usage

From source file:com.example.titan.dynamodb.hystrix.issue.TitanConfigurationProvider.java

public GraphDatabaseConfiguration load() throws ConfigurationException, FileNotFoundException {
    final PropertiesConfiguration configuration = new PropertiesConfiguration();

    // load property file if provided
    if (propertyFile != null) {
        final URL resource = getClass().getClassLoader().getResource(propertyFile);

        if (null == resource) {
            LOG.error("File 'titan.properties' cannot be found.");
            throw new FileNotFoundException("File 'titan.properties' cannot be found.");
        }//from  w  w w .j ava  2s .  co m

        configuration.load(resource);
    }

    configuration.setProperty(STORAGE_HOSTNAME_KEY, storageHostname);

    if (StringUtils.isEmpty(properties.getProperty("storage.dynamodb.client.credentials.class-name"))) {
        properties.remove("storage.dynamodb.client.credentials.class-name");
        properties.remove("storage.dynamodb.client.credentials.constructor-args");
    }

    if (properties != null) {

        properties.stringPropertyNames().stream()
                .forEach(prop -> configuration.setProperty(prop, properties.getProperty(prop)));
    }

    LOG.info("Titan configuration: \n" + secureToString(configuration));

    // Warning: calling GraphDatabaseConfiguration constructor results in opening connections to backend storage
    return new GraphDatabaseConfiguration(new CommonsConfiguration(configuration));
}

From source file:net.sf.zekr.common.util.ConfigUtils.java

/**
 * Loads a configuration properties file (configStream) and close it.
 * //  www .  j a  v  a 2s . c  o m
 * @param configStream
 * @param basePath
 * @param encoding
 * @return
 * @throws ConfigurationException
 * @throws IOException
 */
public static PropertiesConfiguration loadConfig(InputStream configStream, String basePath, String encoding)
        throws ConfigurationException, IOException {
    PropertiesConfiguration pc = new PropertiesConfiguration();
    pc.setThrowExceptionOnMissing(false); // this is the default behavior. just for MOHKAM KARI!
    pc.setEncoding("UTF-8");
    if (basePath != null) {
        pc.setBasePath(basePath);
    }
    pc.load(configStream);
    configStream.close();
    return pc;
}

From source file:io.s4.meter.controller.ControllerModule.java

private void loadProperties(Binder binder) {

    try {/*from  w  ww. ja va  2  s .co  m*/
        InputStream is = this.getClass().getResourceAsStream("/s4-meter.properties");
        config = new PropertiesConfiguration();
        config.load(is);

        System.out.println(ConfigurationUtils.toString(config));
        // TODO - validate properties.

        /* Make all properties injectable. Do we need this? */
        Names.bindProperties(binder, ConfigurationConverter.getProperties(config));
    } catch (ConfigurationException e) {
        binder.addError(e);
        e.printStackTrace();
    }
}

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  ww  w.  j  a va2  s .  c om
        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);
    }
}

From source file:com.linkedin.pinot.core.query.scheduler.resources.UnboundedResourceManagerTest.java

@Test
public void testWithConfig() {
    Configuration config = new PropertiesConfiguration();
    final int workers = 5;
    final int runners = 2;

    config.setProperty(ResourceManager.QUERY_RUNNER_CONFIG_KEY, runners);
    config.setProperty(ResourceManager.QUERY_WORKER_CONFIG_KEY, workers);

    UnboundedResourceManager rm = new UnboundedResourceManager(config);
    assertEquals(rm.getNumQueryWorkerThreads(), workers);
    assertEquals(rm.getNumQueryRunnerThreads(), runners);
    assertEquals(rm.getTableThreadsHardLimit(), runners + workers);
    assertEquals(rm.getTableThreadsSoftLimit(), runners + workers);

    SchedulerGroupAccountant accountant = mock(SchedulerGroupAccountant.class);
    when(accountant.totalReservedThreads()).thenReturn(3);
    assertTrue(rm.canSchedule(accountant));

    when(accountant.totalReservedThreads()).thenReturn(workers + runners + 2);
    assertFalse(rm.canSchedule(accountant));
}

From source file:com.linkedin.pinot.common.segment.fetcher.SegmentFetcherFactoryTest.java

License:asdf

@Test
public void testDefaultSegmentFetcherFactory() throws Exception {
    _segmentFetcherFactory.init(new PropertiesConfiguration());
    Assert.assertTrue(_segmentFetcherFactory.containsProtocol("file"));
    Assert.assertTrue(_segmentFetcherFactory.containsProtocol("http"));
    Assert.assertFalse(_segmentFetcherFactory.containsProtocol("https"));
    Assert.assertFalse(_segmentFetcherFactory.containsProtocol("hdfs"));
}

From source file:com.germinus.easyconf.ConfigurationLearningTest.java

public void testGetFromClasspath() throws ConfigurationException {
    URL result = ConfigurationUtils.locate(null, "test_module.properties");
    assertNotNull(result);/*from www. j a v a2s.  co  m*/
    PropertiesConfiguration conf = new PropertiesConfiguration();
    conf.load("test_module.properties");
    assertEquals("Error reading properties file from classpath", "test_module",
            conf.getString("property-only-in-test-module"));
}

From source file:com.jf.commons.datamodels.hrm.classifiers.Ward.java

public static void generateData(Dao<Ward, Long> dao, Dao<City, Long> cdao, Dao<District, Long> ddao)
        throws Exception {
    // create table if not exists
    TableUtils.createTableIfNotExists(dao.getConnectionSource(), Ward.class);

    // insert wards
    PropertiesConfiguration cfg = new PropertiesConfiguration();
    cfg.load(new InputStreamReader(City.class.getResourceAsStream("wards.properties"), "UTF-8"));
    for (String w : cfg.getStringArray("wards")) {
        String[] parts = w.split(":");

        Ward m = new Ward();
        m.setNew(true);//from  w  w w .  ja v  a 2  s .c om
        m.setName(parts[0].trim());
        m.setDistrict(ddao.queryForEq(District.FIELD_NAME, new SelectArg(parts[1].trim())).get(0));
        m.setCity(cdao.queryForEq(City.FIELD_NAME, new SelectArg(parts[2].trim())).get(0));
        m.setCreator("admin");

        dao.create(m);
    }
}

From source file:com.jf.commons.datamodels.hrm.classifiers.District.java

public static void generateData(Dao<District, Long> dao, Dao<City, Long> cdao) throws Exception {
    // create table if not exists
    TableUtils.createTableIfNotExists(dao.getConnectionSource(), District.class);

    // insert predefine data
    PropertiesConfiguration cfg = new PropertiesConfiguration();
    cfg.load(new InputStreamReader(City.class.getResourceAsStream("districts.properties"), "UTF-8"));
    for (String d : cfg.getStringArray("districts")) {
        String[] district = d.split(":");

        District m = new District();
        m.setNew(true);//www  .  j a  va  2  s  .c o m

        m.setName(district[0].trim());
        m.setCity(cdao.queryForEq(City.FIELD_NAME, new SelectArg(district[1].trim())).get(0));
        m.setCreator("admin");

        dao.create(m);
    }
}

From source file:com.vmware.aurora.util.CommonUtil.java

public static PropertiesConfiguration GetPropertiesConfiguration(String filename)
        throws ConfigurationException {
    PropertiesConfiguration pconf = new PropertiesConfiguration();
    // ','s are value delimiters by default. We don't want ',' delimiters for our error message and properties files
    // as they are not multi-valued. Turn off value delimiters
    // We need to do this before loading the properties
    pconf.setListDelimiter('\0');
    pconf.load(filename);/* ww  w . j a  v  a  2 s .  co m*/
    return pconf;
}