List of usage examples for java.util Properties load
public synchronized void load(InputStream inStream) throws IOException
From source file:com.cloud.utils.PropertiesUtil.java
/** * Load a Properties object with contents from a File. * @param properties the properties object to be loaded * @param file the file to load from//from w w w . j a v a 2 s . c om * @throws IOException */ public static void loadFromFile(Properties properties, File file) throws IOException { InputStream stream = new FileInputStream(file); try { properties.load(stream); } finally { IOUtils.closeQuietly(stream); } }
From source file:edu.duke.cabig.c3pr.utils.DaoTestCase.java
/** * For Oracle typically it is "C3PR_DEV" (note- upper case). For Postgres - "public". Dont * forget to override this depending on your database * //from w w w. java 2 s.c o m * @return */ protected static String getSchema() { URL url = ClassLoader.getSystemResource("context/datasource.properties"); Properties p = new Properties(); try { //p.load(new FileInputStream(new File(url.getFile()))); p.load(url.openStream()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return p.getProperty("datasource.testschema"); }
From source file:com.digitalgeneralists.assurance.Application.java
static void installDb(InputStream propertiesFileStream, InputStream dbScriptStream) throws IOException, SQLException { Logger logger = Logger.getLogger(Application.class); Connection dbConnection = null; ResultSet rs = null;// w w w . j a v a 2 s .c o m try { Properties properties = new Properties(); if (propertiesFileStream != null) { properties.load(propertiesFileStream); } else { throw new FileNotFoundException("The database properties file could not be loaded."); } String dbUrl = (String) properties.get("jdbc.url"); String dbUser = (String) properties.get("jdbc.username"); String dbPassword = (String) properties.get("jdbc.password"); dbConnection = DriverManager.getConnection(dbUrl, dbUser, dbPassword); ArrayList<String> listOfDatabases = new ArrayList<String>(); DatabaseMetaData meta = dbConnection.getMetaData(); String[] tableTypes = { "TABLE" }; rs = meta.getTables(null, null, Application.verificationTableName, tableTypes); while (rs.next()) { String databaseName = rs.getString("TABLE_NAME"); listOfDatabases.add(databaseName.toUpperCase()); } if (listOfDatabases.contains(Application.verificationTableName)) { logger.info("Database already exists"); } else { ScriptRunner runner = new ScriptRunner(dbConnection, true, true); Reader dbScript = new InputStreamReader(dbScriptStream); runner.runScript(dbScript); logger.info("Database is created"); } } finally { if (rs != null) { try { rs.close(); rs = null; } catch (SQLException e) { // The ship is going down. Not much we can do. logger.fatal(e); } } if (dbConnection != null) { dbConnection.close(); dbConnection = null; } } logger = null; }
From source file:com.googleapis.ajax.services.example.ResourceBundleGenerator.java
private static Properties loadResourceMessages(String fileName) { FileInputStream is = null;// www . j av a2s . co m Properties resourceMessages = new Properties(); try { is = new FileInputStream(fileName + ".properties"); resourceMessages.load(is); } catch (Exception ex) { ex.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (Exception e) { } } } return resourceMessages; }
From source file:com.knockturnmc.api.util.ConfigurationUtils.java
/** * Loads a standard Java {@link Properties} file. * If the desired file is not found, a file with the same name will be copied from the classpath to the datafolder. * If no default file was found, an empty file will be created. * * @param classLoader the classloader to use for the default file * @param file the filename to create/load * @param datafolder the datafolder to use * @return the loaded/created file/* ww w .ja v a 2 s . c o m*/ */ public static Properties loadConfiguration(ClassLoader classLoader, String file, File datafolder) { try { File config = getConfigFile(classLoader, file, datafolder); Properties props = new Properties(); try (FileInputStream stream = new FileInputStream(config)) { props.load(stream); } return props; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:cl.niclabs.tscrypto.common.utils.Util.java
public static Properties loadTrimedProperties(String filename) throws IOException { Properties properties = new Properties(); properties.load(new FileInputStream(filename)); trimProperties(properties);//w w w. j a v a2 s . c om return properties; }
From source file:com.buschmais.maexo.test.Constants.java
/** * Load properties file and ignore any exceptions. * /*w ww. j ava 2 s . com*/ * @param classpath resource name * @return properties loaded from classpath resource */ private static Properties getPropertiesFrom(String string) { Properties result = new Properties(); try { InputStream stream = Constants.class.getResourceAsStream("/version.properties"); try { result.load(stream); } finally { stream.close(); } } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:dpfmanager.shell.core.DPFManagerProperties.java
public static String getVersion() { String filename = "version.properties"; InputStream input = MainGuiApp.class.getClassLoader().getResourceAsStream(filename); try {/*from ww w . j av a 2 s. c om*/ // load a properties file Properties prop = new Properties(); prop.load(input); return prop.getProperty("version"); } catch (Exception e) { return ""; } }
From source file:keel.Algorithms.Genetic_Rule_Learning.Falco_GP.Main.java
/** * <p>/*from w w w . jav a 2 s .co m*/ * Configure the execution of the algorithm. * * @param jobFilename Name of the KEEL file with properties of the * execution * </p> */ private static void configureJob(String jobFilename) { Properties props = new Properties(); try { InputStream paramsFile = new FileInputStream(jobFilename); props.load(paramsFile); paramsFile.close(); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(0); } // Files training and test String trainFile; String testFile; StringTokenizer tokenizer = new StringTokenizer(props.getProperty("inputData")); tokenizer.nextToken(); trainFile = tokenizer.nextToken(); trainFile = trainFile.substring(1, trainFile.length() - 1); testFile = tokenizer.nextToken(); testFile = testFile.substring(1, testFile.length() - 1); tokenizer = new StringTokenizer(props.getProperty("outputData")); String reportTrainFile = tokenizer.nextToken(); reportTrainFile = reportTrainFile.substring(1, reportTrainFile.length() - 1); String reportTestFile = tokenizer.nextToken(); reportTestFile = reportTestFile.substring(1, reportTestFile.length() - 1); String reportRulesFile = tokenizer.nextToken(); reportRulesFile = reportRulesFile.substring(1, reportRulesFile.length() - 1); // Algorithm auxiliar configuration XMLConfiguration algConf = new XMLConfiguration(); algConf.setRootElementName("experiment"); algConf.addProperty("process[@algorithm-type]", "net.sourceforge.jclec.problem.classification.falco.FalcoAlgorithm"); algConf.addProperty("process.rand-gen-factory[@type]", "net.sourceforge.jclec.util.random.RanecuFactory"); algConf.addProperty("process.rand-gen-factory[@seed]", Integer.parseInt(props.getProperty("seed"))); algConf.addProperty("process.population-size", Integer.parseInt(props.getProperty("population-size"))); algConf.addProperty("process.max-of-generations", Integer.parseInt(props.getProperty("max-generations"))); algConf.addProperty("process.max-deriv-size", Integer.parseInt(props.getProperty("max-deriv-size"))); algConf.addProperty("process.dataset[@type]", "net.sourceforge.jclec.util.dataset.KeelDataSet"); algConf.addProperty("process.dataset.train-data.file-name", trainFile); algConf.addProperty("process.dataset.test-data.file-name", testFile); algConf.addProperty("process.species[@type]", "net.sourceforge.jclec.problem.classification.falco.FalcoSyntaxTreeSpecies"); algConf.addProperty("process.evaluator[@type]", "net.sourceforge.jclec.problem.classification.falco.FalcoEvaluator"); algConf.addProperty("process.evaluator.alpha", Double.parseDouble(props.getProperty("alpha"))); algConf.addProperty("process.provider[@type]", "net.sourceforge.jclec.syntaxtree.SyntaxTreeCreator"); algConf.addProperty("process.parents-selector[@type]", "net.sourceforge.jclec.selector.RouletteSelector"); algConf.addProperty("process.recombinator[@type]", "net.sourceforge.jclec.syntaxtree.SyntaxTreeRecombinator"); algConf.addProperty("process.recombinator[@rec-prob]", Double.parseDouble(props.getProperty("rec-prob"))); algConf.addProperty("process.recombinator.base-op[@type]", "net.sourceforge.jclec.problem.classification.falco.FalcoCrossover"); algConf.addProperty("process.mutator[@type]", "net.sourceforge.jclec.syntaxtree.SyntaxTreeMutator"); algConf.addProperty("process.mutator[@mut-prob]", Double.parseDouble(props.getProperty("mut-prob"))); algConf.addProperty("process.mutator.base-op[@type]", "net.sourceforge.jclec.problem.classification.falco.FalcoMutator"); algConf.addProperty("process.copy-prob", Double.parseDouble(props.getProperty("copy-prob"))); algConf.addProperty("process.listener[@type]", "net.sourceforge.jclec.problem.classification.falco.KeelFalcoPopulationReport"); algConf.addProperty("process.listener.report-dir-name", "./"); algConf.addProperty("process.listener.train-report-file", reportTrainFile); algConf.addProperty("process.listener.test-report-file", reportTestFile); algConf.addProperty("process.listener.rules-report-file", reportRulesFile); algConf.addProperty("process.listener.global-report-name", "resumen"); algConf.addProperty("process.listener.report-frequency", 50); try { algConf.save(new File("configure.txt")); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } net.sourceforge.jclec.RunExperiment.main(new String[] { "configure.txt" }); }
From source file:Log4jPropertyHelper.java
public static void updateLog4jConfiguration(Class<?> targetClass, String log4jPath) throws Exception { Properties customProperties = new Properties(); FileInputStream fs = null;//from w w w. j a va 2s . co m InputStream is = null; try { fs = new FileInputStream(log4jPath); is = targetClass.getResourceAsStream("/log4j.properties"); customProperties.load(fs); Properties originalProperties = new Properties(); originalProperties.load(is); for (Entry<Object, Object> entry : customProperties.entrySet()) { originalProperties.setProperty(entry.getKey().toString(), entry.getValue().toString()); } LogManager.resetConfiguration(); PropertyConfigurator.configure(originalProperties); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(fs); } }