/** * Load the file and return the contents as a Properties object. * @param file the file to load * @return A Properties object populated * @throws IOException */ public static Properties loadFromFile(final File file) throws IOException { final Properties properties = new Properties(); loadFromFile(properties, file); return properties; }
private synchronized boolean loadFromFile(final File file) { try { PropertiesUtil.loadFromFile(_properties, file); _file = file; } catch (FileNotFoundException e) { s_logger.error("How did we get here? ", e); return false; } catch (IOException e) { s_logger.error("IOException: ", e); return false; } return true; }
public static void initDataSource(String propsFileName) throws IOException { Properties dbProps = new Properties(); File dbPropsFile = PropertiesUtil.findConfigFile(propsFileName); if (dbPropsFile != null && dbPropsFile.exists()) { PropertiesUtil.loadFromFile(dbProps, dbPropsFile); initDataSource(dbProps); } }
public static Map<String, String> processConfigFile(String[] configFiles) { Map<String, String> configMap = new HashMap<String, String>(); Properties preProcessedCommands = new Properties(); for (String configFile : configFiles) { File commandsFile = findConfigFile(configFile); if (commandsFile != null) { try { loadFromFile(preProcessedCommands, commandsFile); } catch (IOException ioe) { s_logger.error("IO Exception loading properties file", ioe); } } else { // in case of a file within a jar in classpath, try to open stream using url try { loadFromJar(preProcessedCommands, configFile); } catch (IOException e) { s_logger.error("IO Exception loading properties file from jar", e); } } } for (Object key : preProcessedCommands.keySet()) { String preProcessedCommand = preProcessedCommands.getProperty((String)key); int splitIndex = preProcessedCommand.lastIndexOf(";"); String value = preProcessedCommand.substring(splitIndex + 1); configMap.put((String)key, value); } return configMap; }
void loadProperties() throws ConfigurationException { final File file = PropertiesUtil.findConfigFile("agent.properties"); if (null == file) { throw new ConfigurationException("Unable to find agent.properties."); } s_logger.info("agent.properties found at " + file.getAbsolutePath()); try { PropertiesUtil.loadFromFile(_properties, file); } catch (final FileNotFoundException ex) { throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex); } catch (final IOException ex) { throw new CloudRuntimeException("IOException in reading " + file.getAbsolutePath(), ex); } }
if (confFile != null) { s_logger.info("Conf file found: " + confFile.getAbsolutePath()); final String pass = PropertiesUtil.loadFromFile(confFile).getProperty(KeyStoreUtils.KS_PASSPHRASE_PROPERTY); if (pass != null) { passphrase = pass.toCharArray();
s_logger.debug("environment.properties could not be opened"); } else { final Properties props = PropertiesUtil.loadFromFile(propsFile); search = props.getProperty("paths.script");
final Properties properties = PropertiesUtil.loadFromFile(confFile); if (properties == null) { return;
@Test public void loadFromFile() throws IOException { File file = File.createTempFile("test", ".properties"); FileUtils.writeStringToFile(file, "a=b\nc=d\n"); Properties properties = new Properties(); PropertiesUtil.loadFromFile(properties, file); Assert.assertEquals("b", properties.get("a")); }
@Test public void loadPropertiesFromFile() throws IOException { File file = File.createTempFile("test", ".properties"); FileUtils.writeStringToFile(file, "a=b\nc=d\n"); Properties properties = PropertiesUtil.loadFromFile(file); Assert.assertEquals("b", properties.get("a")); }
private Map<String, Object> getDeveloperProperties() throws ConfigurationException { final File file = PropertiesUtil.findConfigFile("developer.properties"); if (file == null) { throw new ConfigurationException("Unable to find developer.properties."); } s_logger.info("developer.properties found at " + file.getAbsolutePath()); try { final Properties properties = PropertiesUtil.loadFromFile(file); final String startMac = (String)properties.get("private.macaddr.start"); if (startMac == null) { throw new ConfigurationException("Developers must specify start mac for private ip range"); } final String startIp = (String)properties.get("private.ipaddr.start"); if (startIp == null) { throw new ConfigurationException("Developers must specify start ip for private ip range"); } final Map<String, Object> params = PropertiesUtil.toMap(properties); String endIp = (String)properties.get("private.ipaddr.end"); if (endIp == null) { endIp = getEndIpFromStartIp(startIp, 16); params.put("private.ipaddr.end", endIp); } return params; } catch (final FileNotFoundException ex) { throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex); } catch (final IOException ex) { throw new CloudRuntimeException("IOException in reading " + file.getAbsolutePath(), ex); } }
s_logger.debug("environment.properties could not be opened"); } else { final Properties props = PropertiesUtil.loadFromFile(propsFile); dir = props.getProperty("paths.pid"); if (dir == null) {
final Properties props = PropertiesUtil.loadFromFile(file);
/** * Load the file and return the contents as a Properties object. * * @param file the file to load * @return A Properties object populated * @throws IOException */ public static Properties loadFromFile(final File file) throws IOException { final Properties properties = new Properties(); loadFromFile(properties, file); return properties; } }
public static Map<String, String> processConfigFile(final String[] configFiles) { final Map<String, String> configMap = new HashMap<>(); final Properties preProcessedCommands = new Properties(); for (final String configFile : configFiles) { final File commandsFile = findConfigFile(configFile); if (commandsFile != null) { try { loadFromFile(preProcessedCommands, commandsFile); } catch (final IOException ioe) { s_logger.error("IO Exception loading properties file", ioe); } } else { // in case of a file within a jar in classpath, try to open stream using url try { loadFromJar(preProcessedCommands, configFile); } catch (final IOException e) { s_logger.error("IO Exception loading properties file from jar", e); } } } for (final Object key : preProcessedCommands.keySet()) { final String preProcessedCommand = preProcessedCommands.getProperty((String) key); final int splitIndex = preProcessedCommand.lastIndexOf(";"); final String value = preProcessedCommand.substring(splitIndex + 1); configMap.put((String) key, value); } return configMap; }
s_logger.debug("environment.properties could not be opened"); } else { final Properties props = PropertiesUtil.loadFromFile(propsFile); search = props.getProperty("paths.script");
@Test public void loadFromFile() throws IOException { final File file = File.createTempFile("test", ".properties"); FileUtils.writeStringToFile(file, "a=b\nc=d\n"); final Properties properties = new Properties(); PropertiesUtil.loadFromFile(properties, file); Assert.assertEquals("b", properties.get("a")); }
@Test public void loadPropertiesFromFile() throws IOException { final File file = File.createTempFile("test", ".properties"); FileUtils.writeStringToFile(file, "a=b\nc=d\n"); final Properties properties = PropertiesUtil.loadFromFile(file); Assert.assertEquals("b", properties.get("a")); }
s_logger.debug("environment.properties could not be opened"); } else { final Properties props = PropertiesUtil.loadFromFile(propsFile); dir = props.getProperty("paths.pid"); if (dir == null) {