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

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

Introduction

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

Prototype

public synchronized void load(Reader in) throws ConfigurationException 

Source Link

Document

Load the properties from the given reader.

Usage

From source file:com.liferay.ide.project.core.upgrade.UpgradeMetadataHandler.java

private void updateProperties(IFile file, String propertyName, String propertiesValue) throws Exception {
    File osfile = new File(file.getLocation().toOSString());
    PropertiesConfiguration pluginPackageProperties = new PropertiesConfiguration();
    pluginPackageProperties.load(osfile);
    pluginPackageProperties.setProperty(propertyName, propertiesValue);

    FileWriter output = new FileWriter(osfile);

    try {/*from  ww w  . j av  a 2 s .  co  m*/
        pluginPackageProperties.save(output);
    } finally {
        output.close();
    }

    file.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
}

From source file:es.bsc.autonomic.powermodeller.tools.VariableParser.java

public VariableParser(String filePath, List<String> dataSetHeader) {
    this.dataSetHeader = dataSetHeader;

    PropertiesConfiguration config = new PropertiesConfiguration();
    try {/*w  w w .j a  v  a 2s .c  o m*/
        config.load(filePath);

        columns = new LinkedList(Arrays.asList(config.getStringArray("metrics")));
        for (String column : columns) {
            if (!dataSetHeader.contains(column)) {
                throw new VariableParserException(
                        "Selected metric '" + column + "' does not exist in the provided dataset");
            }
        }

        HashMap<String, String> varDictionary = processRawHM(populateHMFromKeyPrefix("var", config), null);
        newMetrics = processRawHM(populateHMFromKeyPrefix("newmetric", config), varDictionary);

    } catch (ConfigurationException e) {
        logger.error("Error while loading configuration file", e);
        throw new VariableParserException("Error while loading configuration file");
    }
}

From source file:com.vmware.bdd.rest.advice.DefaultExceptionHandler.java

@PostConstruct
private void init() {
    PropertiesConfiguration config = null;
    try {//ww w . j  a  v a  2  s .  c  o m
        config = new PropertiesConfiguration();
        config.setListDelimiter('\0');
        config.load(ERR_CODE_FILE);
    } catch (ConfigurationException ex) {
        // error out if the configuration file is not there
        String message = "Cannot load Serengeti error message file.";
        logger.fatal(message, ex);
        throw BddException.APP_INIT_ERROR(ex, message);
    }
    httpStatusCodes = config;
}

From source file:com.linkedin.pinot.server.api.restlet.TableSizeResourceTest.java

@BeforeTest
public void setupTest() throws Exception {

    INDEX_DIR = Files.createTempDirectory(TableSizeResourceTest.class.getName() + "_segmentDir").toFile();
    File confFile = new File(TestUtils.getFileFromResourceUrl(
            InstanceServerStarter.class.getClassLoader().getResource("conf/pinot.properties")));
    PropertiesConfiguration config = new PropertiesConfiguration();
    config.setDelimiterParsingDisabled(false);
    config.load(confFile);
    ServerConf serverConf = new ServerConf(config);

    LOGGER.info("Trying to create a new ServerInstance!");
    serverInstance = new ServerInstance();
    LOGGER.info("Trying to initial ServerInstance!");
    serverInstance.init(serverConf, new MetricsRegistry());
    LOGGER.info("Trying to start ServerInstance!");
    serverInstance.start();/*from   w  ww.  java  2s . co  m*/
    apiService = new AdminApiService(serverInstance);
    apiService.start(Integer.parseInt(CommonConstants.Server.DEFAULT_ADMIN_API_PORT));
}

From source file:com.linkedin.pinot.server.api.resources.TableSizeResourceTest.java

@BeforeClass
public void setupTest() throws Exception {

    INDEX_DIR = Files.createTempDirectory(TableSizeResourceTest.class.getName() + "_segmentDir").toFile();
    File confFile = new File(TestUtils.getFileFromResourceUrl(
            InstanceServerStarter.class.getClassLoader().getResource("conf/pinot.properties")));
    PropertiesConfiguration config = new PropertiesConfiguration();
    config.setDelimiterParsingDisabled(false);
    config.load(confFile);
    ServerConf serverConf = new ServerConf(config);

    LOGGER.info("Trying to create a new ServerInstance!");
    serverInstance = new ServerInstance();
    LOGGER.info("Trying to initial ServerInstance!");
    serverInstance.init(serverConf, new MetricsRegistry());
    LOGGER.info("Trying to start ServerInstance!");
    serverInstance.start();//from w w w  .j a  v a 2 s.  c om
    apiService = new AdminApiApplication(serverInstance);
    apiService.start(Integer.parseInt(CommonConstants.Server.DEFAULT_ADMIN_API_PORT));
    client = ClientBuilder.newClient();
    target = client.target(apiService.getBaseUri().toString());
    setupSegment();
}

From source file:edu.utexas.cs.tactex.core.BrokerPropertiesService.java

public void setUserConfig(File userConfig) {
    // then load the user-specified config
    try {/* w  w w  .j av a2  s .  c o m*/
        PropertiesConfiguration pconfig = new PropertiesConfiguration();
        pconfig.load(userConfig);
        config.addConfiguration(pconfig);
        log.debug("setUserConfig " + userConfig.getName());
    } catch (ConfigurationException e) {
        log.error("Config error loading " + userConfig + ": " + e.toString());
    }
    lazyInit();
}

From source file:com.linkedin.pinot.server.starter.ServerBuilder.java

/**
 * Construct from config file path/*from w  w w .j  av  a 2s  .  co  m*/
 * @param configFilePath Path to the config file
 * @param metricsRegistry
 * @throws Exception
 */
public ServerBuilder(File configFilePath, MetricsRegistry metricsRegistry) throws Exception {
    this.metricsRegistry = metricsRegistry;
    if (!configFilePath.exists()) {
        LOGGER.error("configuration file: " + configFilePath.getAbsolutePath() + " does not exist.");
        throw new ConfigurationException(
                "configuration file: " + configFilePath.getAbsolutePath() + " does not exist.");
    }

    // build _serverConf
    PropertiesConfiguration serverConf = new PropertiesConfiguration();
    serverConf.setDelimiterParsingDisabled(false);
    serverConf.load(configFilePath);
    _serverConf = new ServerConf(serverConf);

    initMetrics();
}

From source file:io.fluo.mapreduce.FluoInputFormat.java

@Override
public RecordReader<Bytes, ColumnIterator> createRecordReader(InputSplit split, TaskAttemptContext context)
        throws IOException, InterruptedException {

    return new RecordReader<Bytes, ColumnIterator>() {

        private Entry<Bytes, ColumnIterator> entry;
        private RowIterator rowIter;
        private Environment env = null;
        private TransactionImpl ti = null;

        @Override/*from w  ww.j a v a2s  .co m*/
        public void close() throws IOException {
            if (env != null) {
                env.close();
            }
            if (ti != null) {
                ti.close();
            }
        }

        @Override
        public Bytes getCurrentKey() throws IOException, InterruptedException {
            return entry.getKey();
        }

        @Override
        public ColumnIterator getCurrentValue() throws IOException, InterruptedException {
            return entry.getValue();
        }

        @Override
        public float getProgress() throws IOException, InterruptedException {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public void initialize(InputSplit split, TaskAttemptContext context)
                throws IOException, InterruptedException {
            try {
                // TODO this uses non public Accumulo API!
                RangeInputSplit ris = (RangeInputSplit) split;

                Span span = SpanUtil.toSpan(ris.getRange());

                ByteArrayInputStream bais = new ByteArrayInputStream(
                        context.getConfiguration().get(PROPS_CONF_KEY).getBytes("UTF-8"));
                PropertiesConfiguration props = new PropertiesConfiguration();
                props.load(bais);

                env = new Environment(new FluoConfiguration(props));

                ti = new TransactionImpl(env, context.getConfiguration().getLong(TIMESTAMP_CONF_KEY, -1));
                ScannerConfiguration sc = new ScannerConfiguration().setSpan(span);

                for (String fam : context.getConfiguration().getStrings(FAMS_CONF_KEY, new String[0]))
                    sc.fetchColumnFamily(Bytes.wrap(fam));

                rowIter = ti.get(sc);
            } catch (Exception e) {
                throw new IOException(e);
            }
        }

        @Override
        public boolean nextKeyValue() throws IOException, InterruptedException {
            if (rowIter.hasNext()) {
                entry = rowIter.next();
                return true;
            }
            return false;
        }
    };

}

From source file:edu.utexas.cs.tactex.core.BrokerPropertiesService.java

/**
 * Loads the properties from classpath, default config file,
 * and user-specified config file, just in case it's not already been
 * loaded. This is done when properties are first requested, to ensure
 * that the logger has been initialized. Because the CompositeConfiguration
 * treats its config sources in FIFO order, this should be called <i>after</i>
 * any user-specified config is loaded./*from   w  ww  .j  av a  2s.  c  o m*/
 */
void lazyInit() {
    // only do this once
    if (initialized)
        return;
    initialized = true;

    // find and load the default properties file
    log.debug("lazyInit");
    try {
        File defaultProps = new File("broker.properties");
        log.info("adding " + defaultProps.getName());
        config.addConfiguration(new PropertiesConfiguration(defaultProps));
    } catch (Exception e1) {
        log.warn("broker.properties not found: " + e1.toString());
    }

    // set up the classpath props
    try {
        Resource[] xmlResources = context.getResources("classpath*:config/properties.xml");
        for (Resource xml : xmlResources) {
            if (validXmlResource(xml)) {
                log.info("loading config from " + xml.getURI());
                XMLConfiguration xconfig = new XMLConfiguration();
                xconfig.load(xml.getInputStream());
                config.addConfiguration(xconfig);
            }
        }
        Resource[] propResources = context.getResources("classpath*:config/*.properties");
        for (Resource prop : propResources) {
            if (validPropResource(prop)) {
                if (null == prop) {
                    log.error("Null resource");
                }
                log.info("loading config from " + prop.getURI());
                PropertiesConfiguration pconfig = new PropertiesConfiguration();
                pconfig.load(prop.getInputStream());
                config.addConfiguration(pconfig);
            }
        }
    } catch (ConfigurationException e) {
        log.error("Problem loading configuration: " + e.toString());
    } catch (Exception e) {
        log.error("Error loading configuration: " + e.toString());
    }

    // set up the configurator
    configurator.setConfiguration(config);
}

From source file:com.vmware.bdd.rest.RestResource.java

private static org.apache.commons.configuration.Configuration init() {
    PropertiesConfiguration config = null;
    try {//from  w w  w . ja v a 2 s.co m
        config = new PropertiesConfiguration();
        config.setListDelimiter('\0');
        config.load(ERR_CODE_FILE);
    } catch (ConfigurationException ex) {
        // error out if the configuration file is not there
        String message = "Cannot load Serengeti error message file.";
        Logger.getLogger(RestResource.class).fatal(message, ex);
        throw BddException.APP_INIT_ERROR(ex, message);
    }
    return config;
}