List of usage examples for java.util Properties load
public synchronized void load(InputStream inStream) throws IOException
From source file:com.microsoft.tfs.core.telemetry.TfsTelemetryInstrumentationInfo.java
static void initialize(final InputStream in) { // Default to production environment with batch uploading isTestEnv = false;//from www . j a v a 2s. c o m isDeveloperMode = false; if (in != null) { try { final Properties props = new Properties(); try { props.load(in); final String isTestEnvProperty = props .getProperty("telemetry.instrumentation.is_test_environment"); //$NON-NLS-1$ final String isDeveloperModeProperty = props .getProperty("telemetry.instrumentation.is_developer_mode"); //$NON-NLS-1$ // Default to production environment, all invalid inputs // will be resolved as "false" if (!StringUtil.isNullOrEmpty(isTestEnvProperty) && Boolean.parseBoolean(isTestEnvProperty)) { isTestEnv = true; if (!StringUtil.isNullOrEmpty(isDeveloperModeProperty) && Boolean.parseBoolean(isDeveloperModeProperty)) { isDeveloperMode = true; } } } catch (final IOException e) { log.warn(MessageFormat.format("Unable to load property resource {0} with exception {1}", //$NON-NLS-1$ TELEMETRY_INSTRUMENTATION_PROPERTIES_RESOURCE, e)); // suppressing exception } } finally { try { in.close(); } catch (final IOException e) { log.warn(MessageFormat.format("Unable to close property resource {0} with exception {1}", //$NON-NLS-1$ TELEMETRY_INSTRUMENTATION_PROPERTIES_RESOURCE, e)); // suppressing exception } } } }
From source file:com.fluke.database.DatabaseProperty.java
public static DataSource getDataSource() { if (source != null) { return source; }//from w w w.jav a 2s . c o m Properties props = new Properties(); FileInputStream fis = null; BasicDataSource dataSource = new BasicDataSource(); try { props.load(ClassLoader.getSystemResourceAsStream("config/mysql.properties")); dataSource.setDriverClassName(props.getProperty("MYSQL_DB_DRIVER_CLASS")); dataSource.setUrl(props.getProperty("MYSQL_DB_URL")); dataSource.setUsername(props.getProperty("MYSQL_DB_USERNAME")); dataSource.setPassword(props.getProperty("MYSQL_DB_PASSWORD")); } catch (IOException e) { throw new RuntimeException(e); } return source = dataSource; }
From source file:com.rhino.data.db.DataSourceFactory.java
public static DataSource getDataSource() { if (source != null) { return source; }/*from w w w. j ava 2 s .com*/ Properties props = new Properties(); FileInputStream fis = null; BasicDataSource dataSource = new BasicDataSource(); try { props.load(ClassLoader.getSystemResourceAsStream("mysql.properties")); dataSource.setDriverClassName(props.getProperty("MYSQL_DB_DRIVER_CLASS")); dataSource.setUrl(props.getProperty("MYSQL_DB_URL")); dataSource.setUsername(props.getProperty("MYSQL_DB_USERNAME")); dataSource.setPassword(props.getProperty("MYSQL_DB_PASSWORD")); } catch (IOException e) { throw new RuntimeException(e); } return source = dataSource; }
From source file:com.google.mr4c.sources.FilesDatasetSourceConfig.java
private static DirectoryConfig loadDirectoryConfig(Reader reader) throws IOException { ConfigSerializer ser = SerializerFactories.getSerializerFactory("application/json") .createConfigSerializer(); // assume json config for now ser = new ParameterizedConfigSerializer(ser); String content = IOUtils.toString(reader); // need to get this so we can read it twice try {/* w w w . j ava 2 s .c o m*/ return ser.deserializeDirectoryConfig(new StringReader(content)); } catch (JsonParseException jpe) { s_log.warn("Json deserialization failed; trying as properties", jpe); Properties props = new Properties(); props.load(new StringReader(content)); return DirectoryConfig.createFromProperties(props); } }
From source file:name.martingeisse.api.i18n.ClassHierarchyLocalizationContext.java
/** * Loads the .properties file for the origin class and the specified locale and returns * either its contents as a map, or an empty map if the file cannot be found. * /* w w w.j a va2 s . com*/ * This method is static to emphasize that it does not use or affect the calling instance * in any other way. * * @param origin the origin class * @param locale the locale * @return the properties */ private static Map<String, String> loadProperties(Class<?> origin, Locale locale) { String filename = origin.getSimpleName() + '_' + locale + ".properties"; try (InputStream inputStream = origin.getResourceAsStream(filename)) { if (inputStream == null) { @SuppressWarnings("unchecked") Map<String, String> emptyMap = MapUtils.EMPTY_MAP; return emptyMap; } Properties properties = new Properties(); properties.load(inputStream); @SuppressWarnings("unchecked") Map<String, String> typedProperties = (Map<String, String>) (Map<?, ?>) properties; return typedProperties; } catch (IOException e) { logger.error("could not load i18n property file", e); return null; } }
From source file:com.moviejukebox.TestLogger.java
/** * Load properties from a file/*from w w w . java2s . co m*/ * * @param props * @param propertyFile */ public static void loadProperties(Properties props, File propertyFile) { try (InputStream is = new FileInputStream(propertyFile)) { props.load(is); } catch (Exception ex) { LOG.warn("Failed to load properties file", ex); } }
From source file:org.ops4j.pax.web.itest.util.TestConfiguration.java
public static Option paxCdiWithWeldBundles() { Properties props = new Properties(); try {// w ww. j av a2 s .c om props.load(TestConfiguration.class.getResourceAsStream("/systemPackages.properties")); } catch (IOException exc) { throw new Ops4jException(exc); } return composite( // do not treat javax.annotation as system package when(isEquinox()).useOptions(frameworkProperty("org.osgi.framework.system.packages") .value(props.get("org.osgi.framework.system.packages"))), linkBundle("org.ops4j.pax.cdi.weld"), // there is a classloader conflict when adding this dep to the POM mavenBundle("org.ops4j.pax.cdi", "pax-cdi-undertow-weld", "0.8.0"), mavenBundle("com.google.guava", "guava", "13.0.1"), mavenBundle("org.jboss.weld", "weld-osgi-bundle", "2.1.2.Final")); }
From source file:com.bt.aloha.batchtest.JmxScenarioExporter.java
protected static void configure(BatchTest batchTest) throws Exception { Properties properties = new Properties(); InputStream is = new FileInputStream(CONFIG_FILE); properties.load(is); is.close();/*from w ww . j a v a 2 s . com*/ batchTest.setAudioFileUri(properties.getProperty("audioFileUri", "/provisioned/behave.wav")); batchTest.setNumberOfRuns(1); batchTest.setNumberOfConcurrentStarts(1); batchTest.setMaximumScenarioCompletionWaitTimeSeconds( Integer.parseInt(properties.getProperty("maximumScenarioCompletionWaitTimeSeconds", "60"))); batchTest.setExecutorService(Executors.newFixedThreadPool(4)); addBatchScenarios(batchTest); }
From source file:com.groupdocs.ui.Utils.java
public static String getProjectProperty(String name) { Properties p = new Properties(); try (InputStream i = Utils.class.getResourceAsStream("/project.properties")) { p.load(i); } catch (IOException e) { // Ignore }// ww w. java 2s . c o m return p.getProperty(name); }
From source file:org.pmedv.core.util.ResourceUtils.java
/** * Configures a factory from a properties file read from an input stream * /* w w w .ja v a2 s. c om*/ * @param is the stream to read the properties from * @param factory the factory to configure */ public static Properties configureFactoryFromInputStream(InputStream is, XmlBeanFactory factory) { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); Properties p = new Properties(); try { p.load(is); } catch (IOException e) { e.printStackTrace(); } cfg.setProperties(p); cfg.postProcessBeanFactory(factory); return p; }