List of usage examples for java.util Properties load
public synchronized void load(InputStream inStream) throws IOException
From source file:jp.co.opentone.bsol.framework.test.AbstractTestCase.java
@BeforeClass public static void setupClass() throws IOException { Properties p = new Properties(); try {/*from w w w . jav a 2 s. c o m*/ p.load(AbstractTestCase.class.getResourceAsStream("/mail.properties")); wiser = new Wiser(); wiser.setHostname(p.getProperty("mail.host")); wiser.setPort(Integer.valueOf(p.getProperty("mail.port"))); wiser.start(); } catch (IOException e) { throw e; } }
From source file:de.dfki.resc28.ole.bootstrap.App.java
public static synchronized void configure() { try {//w ww. j a va 2 s .com String configFile = System.getProperty("bootstrap.configuration"); java.io.InputStream is; if (configFile != null) { is = new java.io.FileInputStream(configFile); System.out.format("Loading OLE Bootstrapper configuration from %s ...%n", configFile); } else { is = App.class.getClassLoader().getResourceAsStream("bootstrap.properties"); System.out.println("Loading OLE Bootstrapper configuration from internal resource file ..."); } java.util.Properties p = new Properties(); p.load(is); fBaseURI = getProperty(p, "baseURI", "bootstrap.baseURI"); fStorageURI = getProperty(p, "storageURI", "bootstrap.storageURI"); fAssetBaseUri = Util.joinPath(App.fBaseURI, "repo/assets"); fDistributionBaseUri = Util.joinPath(App.fBaseURI, "repo/distributions"); fUserBaseUri = Util.joinPath(App.fBaseURI, "repo/users"); fPartsDirectory = getProperty(p, "partsDirectory", "bootstrap.partsDirectory"); String storage = getProperty(p, "graphStore", "bootstrap.graphStore"); if (storage.equals("fuseki")) { String dataEndpoint = getProperty(p, "dataEndpoint", "bootstrap.dataEndpoint"); String queryEndpoint = getProperty(p, "queryEndpoint", "bootstrap.queryEndpoint"); System.out.format("Use Fuseki backend:%n dataEndpoint=%s%n queryEndpoint=%s ...%n", dataEndpoint, queryEndpoint); fGraphStore = new FusekiGraphStore(dataEndpoint, queryEndpoint); } // Overriders if (fPartsDirectory == null || !new File(fPartsDirectory).isDirectory()) { String ldrawDir = System.getenv("LDRAWDIR"); if (ldrawDir != null) { File dir = new File(ldrawDir); if (dir.isDirectory()) { dir = new File(dir, "parts"); if (dir.isDirectory()) { fPartsDirectory = dir.toString(); } } } } System.out.format("Use LDraw parts directory: %s%n", fPartsDirectory); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
/** * Gets properties from Assets//from w w w . j a va 2 s . co m * * @param name Properties file * @param context Context * @return Properties */ public static Properties getProperties(String name, Context context) { Resources resources = context.getResources(); AssetManager assetManager = resources.getAssets(); Properties properties = null; // Read from the /assets directory try { InputStream inputStream = assetManager.open(name); properties = new Properties(); properties.load(inputStream); } catch (IOException e) { e.printStackTrace(); } return 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 w w 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:net.padlocksoftware.padlock.KeyManager.java
/** * Import a Padlock 2.x (DSA based) KeyPair from an InputStream. The stream is * assumed to have been previously exported in a supported format using the * exportKeyPair methods./*from w w w . j a va 2s . c o m*/ * @param stream The KeyPair stream to import. * @return The DSA KeyPair contained in the specified file. * @throws java.io.IOException If file is missing or contain invalid data. * @since 2.0 */ public static KeyPair importKeyPair(InputStream stream) throws IOException { if (stream == null) throw new IllegalArgumentException("Stream cannot be null"); KeyPair pair = null; Properties p = new Properties(); p.load(stream); stream.close(); String pri = p.getProperty("private"); String pub = p.getProperty("public"); if (pri == null || pub == null) { throw new IOException("Stream data is invalid"); } // Load the keys try { PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(Hex.decodeHex(pri.toCharArray())); KeyFactory keyFactory = KeyFactory.getInstance("DSA"); PrivateKey privateKey = keyFactory.generatePrivate(privateKeySpec); X509EncodedKeySpec pubSpec = new X509EncodedKeySpec(Hex.decodeHex(pub.toCharArray())); PublicKey publicKey = keyFactory.generatePublic(pubSpec); pair = new KeyPair(publicKey, privateKey); } catch (Exception e) { throw new RuntimeException("Invalid stream: " + e.getMessage()); } return pair; }
From source file:com.ms.commons.test.tool.exportdata.DatabasePropertiesLoader.java
private static Properties loadProperties(File file) { Properties properties = new Properties(); FileInputStream fis = null;/*from w w w . ja va2s . c o m*/ try { fis = new FileInputStream(file); properties.load(fis); } catch (Exception e) { throw ExceptionUtil.wrapToRuntimeException(e); } finally { IOUtils.closeQuietly(fis); } return properties; }
From source file:com.google.code.pentahoflashcharts.charts.PentahoOFC4JChartHelper.java
@SuppressWarnings("unchecked") private static Map createChartFactoryMap() { Properties chartFactories = new Properties(); // First, get known chart factories... try {/*from ww w . j a v a 2 s .c om*/ ResourceBundle pluginBundle = ResourceBundle.getBundle(PLUGIN_BUNDLE_NAME); if (pluginBundle != null) { // Copy the bundle here... Enumeration keyEnum = pluginBundle.getKeys(); String bundleKey = null; while (keyEnum.hasMoreElements()) { bundleKey = (String) keyEnum.nextElement(); chartFactories.put(bundleKey, pluginBundle.getString(bundleKey)); } } } catch (Exception ex) { logger.warn(Messages.getString("PentahoOFC4JChartHelper.WARN_NO_CHART_FACTORY_PROPERTIES_BUNDLE")); //$NON-NLS-1$ } // Get overrides... // // Note - If the override wants to remove an existing "known" plugin, // simply adding an empty value will cause the "known" plugin to be removed. // if (PentahoSystem.getObjectFactory() == null || !PentahoSystem.getObjectFactory().objectDefined(ISolutionRepository.class.getSimpleName())) { // this is ok return chartFactories; } ISolutionRepository solutionRepository = PentahoSystem.get(ISolutionRepository.class, new StandaloneSession("system")); //$NON-NLS-1$ try { if (solutionRepository.resourceExists(SOLUTION_PROPS)) { InputStream is = solutionRepository.getResourceInputStream(SOLUTION_PROPS, false); Properties overrideChartFactories = new Properties(); overrideChartFactories.load(is); chartFactories.putAll(overrideChartFactories); // load over the top of the known properties } } catch (FileNotFoundException ignored) { logger.warn(Messages.getString("PentahoOFC4JChartHelper.WARN_NO_CHART_FACTORY_PROPERTIES")); //$NON-NLS-1$ } catch (IOException ignored) { logger.warn(Messages.getString("PentahoOFC4JChartHelper.WARN_BAD_CHART_FACTORY_PROPERTIES"), ignored); //$NON-NLS-1$ } return chartFactories; }
From source file:com.hazelcast.qasonar.utils.PropertyReaderBuilder.java
private static PropertyReader fromPropertyFile(String propertyFileName) throws IOException { Properties props = new Properties(); FileInputStream in = null;/* w w w.ja va2 s . com*/ try { in = new FileInputStream(propertyFileName); props.load(in); } finally { closeQuietly(in); } return fromProperties(props); }
From source file:Main.java
public static Properties getProperties(Context context) { Properties props = new Properties(); // InputStream in = Utils.class.getResourceAsStream("/gewara.properties"); try {/*from www. j av a 2 s.c o m*/ InputStream in = context.getAssets().open("gewara.properties"); props.load(in); } catch (Exception e) { e.printStackTrace(); } return props; }
From source file:de.thischwa.pmcms.tool.ToolVersionInfo.java
private static Map<TYPE, String> getInfoFromMetaPom(final String groupId, final String artifactId) { String pomPath = String.format("META-INF/maven/%s/%s/pom.properties", groupId, artifactId); Map<TYPE, String> info = new HashMap<TYPE, String>(2); info.put(TYPE.title, "unknown"); info.put(TYPE.version, "n/n"); InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(pomPath); if (in != null) { Properties properties = new Properties(); try {/* w w w . j ava2 s . c om*/ in = new BufferedInputStream(in); properties.load(in); } catch (IOException ex) { } String title = properties.getProperty("artifactId"); String version = properties.getProperty("version"); if (title != null) info.put(TYPE.title, title); if (version != null) info.put(TYPE.version, version); } return info; }