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.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.");
        }/* ww w  .  j a  v  a2s .  c o 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:com.aurel.track.dbase.HandleHome.java

/**
 * Gets the PropertiesConfiguration for a property file from servlet context
 * @param propFile// w w  w .j  av  a2 s.c o  m
 * @param servletContext
 * @return
 * @throws ServletException
 */
public static PropertiesConfiguration loadServletContextPropFile(String propFile, ServletContext servletContext)
        throws ServletException {
    PropertiesConfiguration pc = null;
    InputStream in = null;
    URL propFileURL = null;
    try {
        if (pc == null && servletContext != null) {
            propFileURL = servletContext.getResource("/WEB-INF/" + propFile);
            in = propFileURL.openStream();
            pc = new PropertiesConfiguration();
            pc.load(in);
            in.close();
        }
    } catch (Exception e) {
        LOGGER.error("Could not read " + propFile + " from servlet context " + propFileURL == null ? ""
                : propFileURL.toExternalForm() + ". Exiting. " + e.getMessage());
        throw new ServletException(e);
    }
    return pc;
}

From source file:io.fluo.api.config.FluoConfiguration.java

public FluoConfiguration(File propertiesFile) {
    this();/*from  ww  w  .  j a va  2 s.  c om*/
    try {
        PropertiesConfiguration config = new PropertiesConfiguration();
        // disabled to prevent accumulo classpath value from being shortened
        config.setDelimiterParsingDisabled(true);
        config.load(propertiesFile);
        addConfiguration(config);
    } catch (ConfigurationException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:com.aurel.track.dbase.HandleHome.java

public static PropertiesConfiguration getMergedCrmConfiguration(PropertiesConfiguration dbcfg) {
    String propFile = "CrmTorque.properties";
    ClassLoader cl = HandleHome.class.getClassLoader();
    InputStream in = null;/* w w w.ja v a  2s.co  m*/
    try {
        URL torqueURL = cl.getResource(propFile);
        in = torqueURL.openStream();
        if (dbcfg == null) {
            dbcfg = new PropertiesConfiguration();
        }
        dbcfg.load(in);
        in.close();
        if (firstTimeMerge) {
            LOGGER.info("Obtained another database configuration from " + propFile + ".");
            firstTimeMerge = false;
        }
    } catch (Exception e) {
        String emsg = e.getMessage();
        if (emsg == null) {
            emsg = "";
        }
    }
    return dbcfg;
}

From source file:com.nilostep.xlsql.database.xlInstanceOLD.java

private xlInstanceOLD(String cfg) throws xlException {
    logger = Logger.getLogger(this.getClass().getName());
    instance = this;
    //name = cfg;

    try {/*from  ww  w. ja  v a2 s .c  om*/
        //            file = new File(cfg + "_config.xml");
        //            handler = new XMLFileHandler();
        //            handler.setFile(file);
        //
        //            cm = ConfigurationManager.getInstance();
        //            config = cm.getConfiguration(name);
        //            config.addConfigurationListener(this);
        //
        //            if (file.exists()) {

        PropertiesConfiguration config = new PropertiesConfiguration();
        config.load(this.getClass().getResourceAsStream(cfg + ".properties"));
        String engine = config.getString("general.engine");

        //cm.load(handler, name);                
        //Category cat = config.getCategory("general");                                                                
        //engine = config.getProperty("engine", null, "general");
        //config.setCategory(engine, true);
        //logger.info("Configuration file: " + file + " loaded");
        logger.info("Configuration engine: " + engine + " loaded");
        //            } else {

        //
        //                assert (config.isNew());
        //
        //                //
        //                config.setCategory("general", true);
        //
        //                String engine = "hsqldb";
        //                setLog("xlsql.log");
        //                setDatabase(System.getProperty("user.dir"));
        //
        //                //
        //                this.engine = engine;
        //                this.config.setProperty("engine", engine);
        //                addEngine(engine);
        //                config.setCategory(engine, true);
        //
        //
        //                //
        //                setDriver("org.hsqldb.jdbcDriver");
        //                setUrl("jdbc:hsqldb:.");
        //                setSchema("");
        //                setUser("sa");
        //                setPassword("");
        //                config.setCategory(getEngine(), true);
        //                logger.info("Configuration file: " + file + " created.");
        //            }
    }
    //catch (ConfigurationManagerException cme) {
    //   config = cm.getConfiguration(name);
    //} 
    catch (ConfigurationException e) {
        e.printStackTrace();
        throw new xlException(e.getMessage());
    }

    try {
        if (getLog() == null) {
            setLog("xlsql.log");
        }

        boolean append = true;
        FileHandler loghandler = new FileHandler(getLog(), append);
        loghandler.setFormatter(new SimpleFormatter());
        logger.addHandler(loghandler);
    } catch (IOException e) {
        throw new xlException("error while creating logfile");
    }

    //logger.info("Instance created with engine " + getEngine());
    logger.info("Instance created with engine " + engine);

    //
    //
    //
}

From source file:com.kylinolap.common.KylinConfig.java

void reloadKylinConfig(InputStream is) {
    PropertiesConfiguration config = new PropertiesConfiguration();
    try {//from  w w  w.  ja  v a2 s .com
        config.load(is);
    } catch (ConfigurationException e) {
        throw new RuntimeException("Cannot load kylin config.", e);
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            logger.error("Failed to close inputstream.", e);
        }
    }
    this.kylinConfig = config;
}

From source file:com.linkedin.pinot.query.executor.BrokerReduceServiceTest.java

@BeforeClass
public void setup() throws Exception {
    TableDataManagerProvider.setServerMetrics(new ServerMetrics(new MetricsRegistry()));

    File confDir = new File(QueryExecutorTest.class.getClassLoader().getResource("conf").toURI());
    setupSegmentList(2);/*  www.  j a  v  a2  s.  c o m*/
    FileUtils.deleteDirectory(new File("/tmp/pinot/test1"));
    // ServerBuilder serverBuilder = new ServerBuilder(confDir.getAbsolutePath());
    String configFilePath = confDir.getAbsolutePath();

    // build _serverConf
    PropertiesConfiguration serverConf = new PropertiesConfiguration();
    serverConf.setDelimiterParsingDisabled(false);
    serverConf.load(new File(configFilePath, PINOT_PROPERTIES));

    FileBasedInstanceDataManager instanceDataManager1 = FileBasedInstanceDataManager.getInstanceDataManager();
    instanceDataManager1
            .init(new FileBasedInstanceDataManagerConfig(serverConf.subset("pinot.server.instance")));
    instanceDataManager1.start();
    for (int i = 0; i < 2; ++i) {
        instanceDataManager1.getTableDataManager("midas");
        instanceDataManager1.getTableDataManager("midas").addSegment(_indexSegmentList.get(i));
    }
    _queryExecutor = new ServerQueryExecutorV1Impl();
    _queryExecutor.init(serverConf.subset("pinot.server.query.executor"), instanceDataManager1,
            new ServerMetrics(new MetricsRegistry()));
}

From source file:com.uber.stream.kafka.mirrormaker.manager.rest.TestManagerTopicManagement.java

void updateHelixConfigFile(String zk, String instanceId, int id) {
    // load helix config from file
    String helixFileName = "src/test/resources/helix.properties";
    PropertiesConfiguration helixConfigFromFile = new PropertiesConfiguration();
    helixConfigFromFile.setDelimiterParsingDisabled(true);
    try {/*from ww w  .  j  av  a2  s.  c  om*/
        helixConfigFromFile.load(helixFileName);
    } catch (Exception e) {
        throw new RuntimeException("Failed to load config from file " + helixFileName + ": " + e.getMessage());
    }

    OutputStream output = null;

    try {
        output = new FileOutputStream("/tmp/helix.properties-" + id);
        // set the properties value
        helixConfigFromFile.setProperty("federated.deployment.name", DEPLOYMENT_NAME);
        helixConfigFromFile.setProperty("zkServer", zk);
        helixConfigFromFile.setProperty("instanceId", instanceId);
        // save properties to project tmp folder
        helixConfigFromFile.save(output);

    } catch (Exception io) {
        io.printStackTrace();
    } finally {
        if (output != null) {
            try {
                output.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.uber.stream.kafka.mirrormaker.manager.rest.TestManagerTopicManagement.java

void updateConsumerConfigFile(String zk, String instanceId, int id) {
    // load consumer config from file
    String consumerFileName = "src/test/resources/consumer.properties";
    PropertiesConfiguration consumerConfigFromFile = new PropertiesConfiguration();
    consumerConfigFromFile.setDelimiterParsingDisabled(true);
    try {/*from w  w  w  . jav  a 2 s .com*/
        consumerConfigFromFile.load(consumerFileName);
    } catch (Exception e) {
        throw new RuntimeException(
                "Failed to load config from file " + consumerFileName + ": " + e.getMessage());
    }

    OutputStream output = null;

    try {
        output = new FileOutputStream("/tmp/consumer.properties-" + id);
        // set the properties value
        consumerConfigFromFile.setProperty("zookeeper.connect", zk);
        consumerConfigFromFile.setProperty("client.id", instanceId);
        // save properties to project tmp folder
        consumerConfigFromFile.save(output);

    } catch (Exception io) {
        io.printStackTrace();
    } finally {
        if (output != null) {
            try {
                output.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.uber.stream.kafka.mirrormaker.manager.rest.TestManagerTopicManagement.java

void updateProducerConfigFile(String instanceId, int id) {
    // load producer config from file
    String producerFileName = "src/test/resources/producer.properties";
    PropertiesConfiguration producerConfigFromFile = new PropertiesConfiguration();
    producerConfigFromFile.setDelimiterParsingDisabled(true);
    try {/*w w w. j  av a 2s .  co m*/
        producerConfigFromFile.load(producerFileName);
    } catch (Exception e) {
        throw new RuntimeException(
                "Failed to load config from file " + producerFileName + ": " + e.getMessage());
    }

    OutputStream output = null;

    try {
        output = new FileOutputStream("/tmp/producer.properties-" + id);
        // set the properties value
        producerConfigFromFile.setProperty("bootstrap.servers", KafkaStarterUtils.DEFAULT_KAFKA_BROKER);
        producerConfigFromFile.setProperty("client.id", instanceId);
        // save properties to project tmp folder
        producerConfigFromFile.save(output);

    } catch (Exception io) {
        io.printStackTrace();
    } finally {
        if (output != null) {
            try {
                output.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}