List of usage examples for org.apache.commons.configuration2 PropertiesConfiguration read
@Override public void read(final Reader in) throws ConfigurationException, IOException
From source file:com.smartmarmot.dbforbix.config.Config.java
/** * Reads the configuration from a properties file * // www. j a v a 2 s . c o m * @throws IOException */ public void readFileConfig() throws IOException, NullPointerException { LOG.debug("Parsing config file: " + configFile); calculateFileConfigHash(); try (FileReader reader = new FileReader(configFile)) { PropertiesConfiguration pcfg = new PropertiesConfiguration(); pcfg.read(reader); if (pcfg.containsKey(SET_PERSISTENCETYPE)) persistenceType = pcfg.getString(SET_PERSISTENCETYPE); if (pcfg.containsKey(SET_PERSISTENCEDIR)) persistenceDir = pcfg.getString(SET_PERSISTENCEDIR); if (pcfg.containsKey(SET_UPDATECONFIG)) setUpdateConfigTimeout(pcfg.getInt(SET_UPDATECONFIG)); if (pcfg.containsKey(SET_POOL_MAXACTIVE)) maxActive = pcfg.getInt(SET_POOL_MAXACTIVE); if (pcfg.containsKey(SET_POOL_MAXIDLE)) maxIdle = pcfg.getInt(SET_POOL_MAXIDLE); if (pcfg.containsKey(SET_LOGIN_TIMEOUT)) loginTimeout = Integer.parseInt(pcfg.getString(SET_LOGIN_TIMEOUT)); Iterator<?> it; it = pcfg.getKeys(GLOBAL_ZBXSRV); while (it.hasNext()) { String key = it.next().toString(); String[] keyparts = key.split("\\."); if (keyparts.length == 3) readConfigZSRV(keyparts[0], keyparts[1], keyparts[2], pcfg.getString(key)); } it = pcfg.getKeys(GLOBAL_DB); while (it.hasNext()) { String key = it.next().toString(); String[] keyparts = key.split("\\."); if (keyparts.length == 3) readConfigDB(keyparts[0], keyparts[1], keyparts[2], pcfg.getString(key)); } } catch (ConfigurationException e) { throw new IOException("Error in configuration: " + e.getLocalizedMessage(), e); } }
From source file:org.exist.launcher.LauncherWrapper.java
public static PropertiesConfiguration getVMProperties() { final PropertiesConfiguration vmProperties = new PropertiesConfiguration(); final java.nio.file.Path propFile = ConfigurationHelper.lookup("vm.properties"); InputStream is = null;/*from ww w . ja v a2 s . co m*/ try { if (Files.isReadable(propFile)) { is = Files.newInputStream(propFile); } if (is == null) { is = LauncherWrapper.class.getResourceAsStream("vm.properties"); } if (is != null) { vmProperties.read(new InputStreamReader(is, "UTF-8")); } } catch (final IOException e) { System.err.println("vm.properties not found"); } catch (ConfigurationException e) { System.err.println("exception reading vm.properties: " + e.getMessage()); } finally { if (is != null) { try { is.close(); } catch (final IOException ioe) { ioe.printStackTrace(); } } } return vmProperties; }
From source file:org.linqs.psl.config.Config.java
public static void loadResource(InputStream stream, String resourceName) { try {//w ww.j a v a 2 s.co m PropertiesConfiguration props = new PropertiesConfiguration(); props.read(new InputStreamReader(stream)); config.append(props); } catch (IOException | ConfigurationException ex) { throw new RuntimeException("Failed to load config resource: " + resourceName, ex); } log.debug("Configuration stream loaded: {}", resourceName); }
From source file:org.linqs.psl.config.Config.java
public static void loadResource(String path) { try {/*ww w . j a v a2 s .c o m*/ PropertiesConfiguration props = new PropertiesConfiguration(); props.read(new FileReader(path)); config.append(props); } catch (IOException | ConfigurationException ex) { throw new RuntimeException("Failed to load config resource: " + path, ex); } log.debug("Configuration file loaded: {}", path); }