List of usage examples for java.util Properties Properties
public Properties()
From source file:edu.berkeley.compbio.ncbitaxonomy.service.NcbiTaxonomyServicesContextFactory.java
public static ApplicationContext makeNcbiTaxonomyServicesContext() throws IOException { File propsFile = PropertiesUtils.findPropertiesFile("NCBI_TAXONOMY_SERVICE_PROPERTIES", ".ncbitaxonomy", "service.properties"); logger.debug("Using properties file: " + propsFile); Properties p = new Properties(); FileInputStream is = null;/*from ww w . j a v a2 s . c o m*/ try { is = new FileInputStream(propsFile); p.load(is); } finally { is.close(); } String dbName = (String) p.get("default"); Map<String, Properties> databases = PropertiesUtils.splitPeriodDelimitedProperties(p); GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.loadBeanDefinitions(new ClassPathResource("ncbitaxonomyclient.xml")); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); Properties properties = databases.get(dbName); if (properties == null) { logger.error("Service definition not found: " + dbName); logger.error("Valid names: " + StringUtils.join(databases.keySet().iterator(), ", ")); throw new NcbiTaxonomyRuntimeException("Database definition not found: " + dbName); } cfg.setProperties(properties); ctx.addBeanFactoryPostProcessor(cfg); ctx.refresh(); // add a shutdown hook for the above context... ctx.registerShutdownHook(); return ctx; }
From source file:com.twitter.hraven.Cluster.java
static void loadHadoopClustersProps(String filename) { // read the property file // populate the map Properties prop = new Properties(); if (StringUtils.isBlank(filename)) { filename = Constants.HRAVEN_CLUSTER_PROPERTIES_FILENAME; }// ww w. j a v a 2s . c o m try { //TODO : property file to be moved out from resources into config dir InputStream inp = Cluster.class.getResourceAsStream("/" + filename); if (inp == null) { LOG.error(filename + " for mapping clusters to cluster identifiers in hRaven does not exist"); return; } prop.load(inp); Set<String> hostnames = prop.stringPropertyNames(); for (String h : hostnames) { CLUSTERS_BY_HOST.put(h, prop.getProperty(h)); } } catch (IOException e) { // An ExceptionInInitializerError will be thrown to indicate that an // exception occurred during evaluation of a static initializer or the // initializer for a static variable. throw new ExceptionInInitializerError(" Could not load properties file " + filename + " for mapping clusters to cluster identifiers in hRaven"); } }
From source file:com.github.dbourdette.glass.job.util.JobDataMapUtils.java
public static JobDataMap fromProperties(String dataMap) { if (StringUtils.isEmpty(dataMap)) { return new JobDataMap(); }/*w w w .j a v a 2s . c om*/ Properties props = new Properties(); try { props.load(new StringReader(dataMap)); } catch (IOException e) { throw new RuntimeException(e); } JobDataMap map = new JobDataMap(); for (Object key : props.keySet()) { map.put(key, props.getProperty((String) key)); } return map; }
From source file:com.siemens.scr.avt.ad.io.BatchLoader.java
protected static void initLogging() { try {//from w w w .ja v a 2 s. c o m Properties props = new Properties(); props.load(ClassLoader.getSystemResource("log4j.properties").openStream()); PropertyConfigurator.configure(props); } catch (Exception e) { System.err.println("unable to load log4j.properties"); } }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.DBTestUtil.java
public static void setDataSourceFromPropertyFile() throws Exception { InputStream inputStream = DeviceDAOImplTest.class.getResourceAsStream("/test.properties"); Properties testProperties = new Properties(); testProperties.load(inputStream);/*from ww w . j a v a2s. c o m*/ String host = testProperties.getProperty("db.host"); String port = testProperties.getProperty("db.port"); String user = testProperties.getProperty("db.user"); String password = testProperties.getProperty("db.password"); String driver = testProperties.getProperty("db.driver"); String schema = testProperties.getProperty("db.schema"); String url = "jdbc:mysql://" + host + ":" + port + "/" + schema; ds = new BasicDataSource(); ds.setDriverClassName(driver); ds.setUsername(user); ds.setPassword(password); ds.setUrl(url); }
From source file:com.gc.core.framework.utils.PropertiesUtils.java
/** * properties, ???.// ww w. j av a 2 s.c o m * Spring Resource?, ?UTF-8. * * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer */ public static Properties loadProperties(String... resourcesPaths) throws IOException { Properties props = new Properties(); for (String location : resourcesPaths) { logger.debug("Loading properties file from:" + location); InputStream is = null; try { Resource resource = resourceLoader.getResource(location); is = resource.getInputStream(); propertiesPersister.load(props, new InputStreamReader(is, DEFAULT_ENCODING)); } catch (IOException ex) { logger.info("Could not load properties from classpath:" + location + ": " + ex.getMessage()); } finally { if (is != null) { is.close(); } } } return props; }
From source file:com.honnix.cheater.util.PropertiesLoader.java
public static Properties loadProperties(final String fileName) { Properties properties = null; synchronized (PropertiesLoader.class) { properties = propertiesMap.get(fileName); if (properties == null) { properties = new Properties(); try { properties.load(PropertiesLoader.class.getClassLoader().getResourceAsStream(fileName)); propertiesMap.put(fileName, properties); } catch (IOException e) { StringBuilder sb = new StringBuilder("Could not find ").append(fileName) .append(" in class loading path."); LOG.fatal(sb.toString()); properties = null;/*from w w w . j av a 2 s. c o m*/ } } } return properties; }
From source file:agency.AgencyManagerImplTest.java
private static DataSource prepareDataSource() throws SQLException, IOException { Properties myconf = new Properties(); myconf.load(Agency.class.getResourceAsStream("/myconf.properties")); BasicDataSource ds = new BasicDataSource(); ds.setUrl(myconf.getProperty("jdbc.url")); ds.setUsername(myconf.getProperty("jdbc.user")); ds.setPassword(myconf.getProperty("jdbc.password")); return ds;//from w w w.j a v a 2 s . com }
From source file:PooledConnectionExample.java
private static InitialContext createContext() throws NamingException { Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory"); env.put(Context.PROVIDER_URL, "rmi://localhost:1099"); InitialContext context = new InitialContext(env); return context; }
From source file:com.intel.mtwilson.fs.ConfigurableFeatureFilesystem.java
public ConfigurableFeatureFilesystem() { this(new MapConfiguration(new Properties())); }