List of usage examples for org.apache.commons.configuration PropertiesConfiguration load
public synchronized void load(Reader in) throws ConfigurationException
From source file:GenerateWorkItems.java
private static void initTorque() { try {//from w w w . j a va2 s . c om PropertiesConfiguration tcfg = new PropertiesConfiguration(); URL torqueURL = GenerateWorkItems.class.getResource("/Torque.properties"); InputStream in = torqueURL.openStream(); tcfg.load(in); /*tcfg.setProperty("torque.dsfactory.track.connection.user", "sysdba"); tcfg.setProperty("torque.dsfactory.track.connection.password", "masterkey"); tcfg.setProperty("torque.database.track.adapter", "firebird"); tcfg.setProperty("torque.dsfactory.track.connection.driver", "org.firebirdsql.jdbc.FBDriver"); tcfg.setProperty("torque.dsfactory.track.connection.url", "jdbc:firebirdsql://localhost/C:/Firebird_1_5/databases/TEST34.GDB"); tcfg.setProperty("torque.dsfactory.track.factory", "org.apache.torque.dsfactory.SharedPoolDataSourceFactory"); tcfg.setProperty("torque.dsfactory.track.pool.maxActive", "30"); tcfg.setProperty("torque.dsfactory.track.pool.testOnBorrow","true"); tcfg.setProperty("torque.dsfactory.track.pool.validationQuery","SELECT PKEY FROM TSTATE"); */ tcfg.setProperty("torque.applicationRoot", "."); tcfg.setProperty("torque.database.default", "track"); tcfg.setProperty("torque.idbroker.clever.quantity", new Boolean(false)); tcfg.setProperty("torque.idbroker.prefetch", new Boolean(false)); tcfg.setProperty("torque.manager.useCache", new Boolean(true)); in.close(); Torque.init(tcfg); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.sf.zekr.common.util.ConfigUtils.java
/** * Loads a configuration properties file (configStream) and close it. * //from w ww . j a v a 2 s . 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:gobblin.util.JobConfigurationUtils.java
/** * Load the properties from the specified file into a {@link Properties} object. * * @param fileName the name of the file to load properties from * @param conf configuration object to determine the file system to be used * @return a new {@link Properties} instance */// www . ja va 2 s . c o m public static Properties fileToProperties(String fileName, Configuration conf) throws IOException, ConfigurationException { PropertiesConfiguration propsConfig = new PropertiesConfiguration(); Path filePath = new Path(fileName); URI fileURI = filePath.toUri(); if (fileURI.getScheme() == null && fileURI.getAuthority() == null) { propsConfig.load(FileSystem.getLocal(conf).open(filePath)); } else { propsConfig.load(filePath.getFileSystem(conf).open(filePath)); } return ConfigurationConverter.getProperties(propsConfig); }
From source file:com.pinterest.pinlater.backends.mysql.PinLaterMySQLBackendTest.java
@BeforeClass public static void beforeClass() throws Exception { QUEUE_NAME = "pinlater_mysql_backend_test"; // If there is no local MySQL, skip this test. boolean isLocalMySQLRunning = LocalMySQLChecker.isRunning(); Assume.assumeTrue(isLocalMySQLRunning); PropertiesConfiguration configuration = new PropertiesConfiguration(); try {/*from w w w.j av a2 s .com*/ configuration.load(ClassLoader.getSystemResourceAsStream("pinlater.test.properties")); } catch (ConfigurationException e) { throw new RuntimeException(e); } System.setProperty("backend_config", "mysql.local.json"); backend = new PinLaterMySQLBackend(configuration, "localhost", System.currentTimeMillis()); }
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); return pconf; }
From source file:com.tesora.dve.common.PEFileUtils.java
public static PropertiesConfiguration loadPropertiesConfigFromClasspath(Class<?> testClass, String fileName) throws PEException { PropertiesConfiguration props = new PropertiesConfiguration(); try {//w w w . j a v a 2s .co m props.load(getResourceStream(testClass, fileName)); } catch (ConfigurationException e) { throw new PEException("Error loading properties file '" + fileName + "'", e); } return props; }
From source file:com.aurel.track.util.PropertiesConfigurationHelper.java
/** * Gets the PropertiesConfiguration for a property file from servlet context * @param servletContext// w ww . ja va2s . c om * @param pathWithinContext * @param propFile * @return * @throws ServletException */ public static PropertiesConfiguration loadServletContextPropFile(ServletContext servletContext, String pathWithinContext, String propFile) throws ServletException { PropertiesConfiguration propertiesConfiguration = null; InputStream in = null; URL propFileURL = null; try { if (servletContext != null && pathWithinContext != null) { if (!pathWithinContext.startsWith("/")) { pathWithinContext = "/" + pathWithinContext; } if (!pathWithinContext.endsWith("/")) { pathWithinContext = pathWithinContext + "/"; } propFileURL = servletContext.getResource(pathWithinContext + propFile); in = propFileURL.openStream(); propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.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 propertiesConfiguration; }
From source file:com.uber.stream.kafka.mirrormaker.manager.ManagerConf.java
public static ManagerConf getManagerConf(CommandLine cmd) { ManagerConf managerConf = new ManagerConf(); if (cmd.hasOption("config")) { managerConf.setConfigFile(cmd.getOptionValue("config")); } else {/*w w w. j a v a 2 s .c o m*/ managerConf.setConfigFile(""); } if (cmd.hasOption("srcClusters")) { managerConf.setSourceClusters(cmd.getOptionValue("srcClusters")); } else { managerConf.setSourceClusters(""); } if (cmd.hasOption("destClusters")) { managerConf.setDestinationClusters(cmd.getOptionValue("destClusters")); } else { managerConf.setDestinationClusters(""); } if (cmd.hasOption("enableRebalance")) { managerConf.setEnableRebalance(cmd.getOptionValue("enableRebalance")); } else { managerConf.setEnableRebalance(Boolean.toString(DEFAULT_ENABLE_REBALANCE)); } if (cmd.hasOption("zookeeper")) { managerConf.setManagerZkStr(cmd.getOptionValue("zookeeper")); } else { throw new RuntimeException("Missing option: --zookeeper"); } if (cmd.hasOption("managerPort")) { managerConf.setManagerPort(cmd.getOptionValue("managerPort")); } else { throw new RuntimeException("Missing option: --managerPort"); } if (cmd.hasOption("deployment")) { managerConf.setManagerDeployment(cmd.getOptionValue("deployment")); } else { throw new RuntimeException("Missing option: --deployment"); } if (cmd.hasOption("env")) { managerConf.setEnvironment(cmd.getOptionValue("env")); } else { throw new RuntimeException("Missing option: --env"); } if (cmd.hasOption("instanceId")) { managerConf.setManagerInstanceId(cmd.getOptionValue("instanceId")); } else { try { managerConf.setManagerInstanceId(InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException e) { throw new RuntimeException("Missing option: --instanceId"); } } if (cmd.hasOption("controllerPort")) { managerConf.setControllerPort(cmd.getOptionValue("controllerPort")); } else { throw new RuntimeException("Missing option: --controllerPort"); } if (cmd.hasOption("graphiteHost")) { managerConf.setGraphiteHost(cmd.getOptionValue("graphiteHost")); } if (cmd.hasOption("graphitePort")) { managerConf.setGraphitePort(cmd.getOptionValue("graphitePort")); } else { managerConf.setGraphitePort("0"); } if (cmd.hasOption("metricsPrefix")) { managerConf.setMetricsPrefix(cmd.getOptionValue("metricsPrefix")); } else { managerConf.setMetricsPrefix(DEFAULT_METRICS_PREFIX); } if (cmd.hasOption("c3Host")) { managerConf.setC3Host(cmd.getOptionValue("c3Host")); } else { managerConf.setC3Host(DEFAULT_C3_HOST); } if (cmd.hasOption("c3Port")) { managerConf.setC3Port(cmd.getOptionValue("c3Port")); } else { managerConf.setC3Port(Integer.toString(DEFAULT_C3_PORT)); } if (cmd.hasOption("clusterPrefixLength")) { managerConf.setClusterPrefixLength(cmd.getOptionValue("clusterPrefixLength")); } else { managerConf.setClusterPrefixLength(Integer.toString(DEFAULT_CLUSTER_PREFIX_LENGTH)); } if (cmd.hasOption("workloadRefreshPeriodInSeconds")) { managerConf.setWorkloadRefreshPeriodInSeconds(cmd.getOptionValue("workloadRefreshPeriodInSeconds")); } else { managerConf.setWorkloadRefreshPeriodInSeconds( Integer.toString(DEFAULT_WORKLOAD_REFRESH_PERIOD_IN_SECONDS)); } if (cmd.hasOption("initMaxNumPartitionsPerRoute")) { managerConf.setInitMaxNumPartitionsPerRoute(cmd.getOptionValue("initMaxNumPartitionsPerRoute")); } else { managerConf .setInitMaxNumPartitionsPerRoute(Integer.toString(DEFAULT_INIT_MAX_NUM_PARTITIONS_PER_ROUTE)); } if (cmd.hasOption("maxNumPartitionsPerRoute")) { managerConf.setMaxNumPartitionsPerRoute(cmd.getOptionValue("maxNumPartitionsPerRoute")); } else { managerConf.setMaxNumPartitionsPerRoute(Integer.toString(DEFAULT_MAX_NUM_PARTITIONS_PER_ROUTE)); } if (cmd.hasOption("initMaxNumWorkersPerRoute")) { managerConf.setInitMaxNumWorkersPerRoute(cmd.getOptionValue("initMaxNumWorkersPerRoute")); } else { managerConf.setInitMaxNumWorkersPerRoute(Integer.toString(DEFAULT_INIT_MAX_NUM_WORKERS_PER_ROUTE)); } if (cmd.hasOption("maxNumWorkersPerRoute")) { managerConf.setMaxNumWorkersPerRoute(cmd.getOptionValue("maxNumWorkersPerRoute")); } else { managerConf.setMaxNumWorkersPerRoute(Integer.toString(DEFAULT_MAX_NUM_WORKERS_PER_ROUTE)); } if (cmd.hasOption("bytesPerSecondDefault")) { managerConf.setBytesPerSecondDefault(cmd.getOptionValue("bytesPerSecondDefault")); } else { managerConf.setBytesPerSecondDefault(Double.toString(DEFAULT_BYTES_PER_SECOND_DEFAULT)); } if (cmd.hasOption("msgsPerSecondDefault")) { managerConf.setMsgsPerSecondDefault(cmd.getOptionValue("msgsPerSecondDefault")); } else { managerConf.setMsgsPerSecondDefault(Double.toString(DEFAULT_MSGS_PER_SECOND_DEFAULT)); } if (cmd.hasOption("updateStatusCoolDownMs")) { managerConf.setUpdateStatusCoolDownMs(cmd.getOptionValue("updateStatusCoolDownMs")); } else { managerConf.setUpdateStatusCoolDownMs(Integer.toString(DEFAULT_UPDATE_STATUS_COOL_DOWN_MS)); } if (cmd.hasOption("config")) { String fileName = cmd.getOptionValue("config"); managerConf.setConfigFile(fileName); // load config from file PropertiesConfiguration configFromFile = new PropertiesConfiguration(); configFromFile.setDelimiterParsingDisabled(true); try { configFromFile.load(fileName); } catch (ConfigurationException e) { throw new RuntimeException("Failed to load config from file " + fileName + ": " + e.getMessage()); } // merge the config with command line. Option from command line has higher priority to override config from file @SuppressWarnings("unchecked") Iterator<String> keyIter = configFromFile.getKeys(); while (keyIter.hasNext()) { String key = keyIter.next(); if (!managerConf.containsKey(key)) { managerConf.addPropertyDirect(key, configFromFile.getProperty(key)); } } } else { managerConf.setConfigFile(""); } return managerConf; }
From source file:com.aurel.track.util.PropertiesConfigurationHelper.java
/** * Obtain the Torque.properties from TRACKPLUS_HOME or if not available from the WAR. * @return//from ww w .j a va 2 s . c om */ public static PropertiesConfiguration getPathnamePropFile(String absolutePath, String propFile) { PropertiesConfiguration propertiesConfiguration = null; File props = null; InputStream in = null; try { // First check if we have a configuration file pointed to by the environment if (absolutePath != null && !"".equals(absolutePath)) { props = new File(absolutePath + File.separator + propFile); LOGGER.debug("Trying file " + absolutePath + File.separator + propFile); if (props.exists() && props.canRead()) { LOGGER.info("Retrieving configuration from " + absolutePath + File.separator + propFile); in = new FileInputStream(props); propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.load(in); in.close(); } } } catch (Exception e) { LOGGER.warn("Could not read " + propFile + " from " + absolutePath + ". Exiting. " + e.getMessage()); } return propertiesConfiguration; }
From source file:com.mirth.connect.server.controllers.tests.TestUtils.java
public static Properties getSqlProperties() { PropertiesConfiguration mirthProperties = new PropertiesConfiguration(); try {/*from w w w . j ava 2 s . c om*/ InputStream is = ResourceUtil.getResourceStream(SqlSession.class, "mirth.properties"); mirthProperties.setDelimiterParsingDisabled(true); mirthProperties.load(is); IOUtils.closeQuietly(is); } catch (Exception e) { e.printStackTrace(); return null; } Properties donkeyProperties = new Properties(); donkeyProperties.setProperty("database.driver", mirthProperties.getString("database.driver")); donkeyProperties.setProperty("database.url", mirthProperties.getString("database.url")); donkeyProperties.setProperty("database.username", mirthProperties.getString("database.username")); if (mirthProperties.containsKey("database.password")) { donkeyProperties.setProperty("database.password", mirthProperties.getString("database.password")); } return donkeyProperties; }