List of usage examples for java.util Properties load
public synchronized void load(InputStream inStream) throws IOException
From source file:com.omertron.fanarttvapi.TestLogger.java
/** * Load properties from a file//from w w w . j ava 2 s . com * * @param props * @param propertyFile */ public static void loadProperties(Properties props, File propertyFile) { InputStream is = null; try { is = new FileInputStream(propertyFile); props.load(is); } catch (Exception ex) { LOG.warn("Failed to load properties file", ex); } finally { if (is != null) { try { is.close(); } catch (IOException ex) { LOG.warn("Failed to close properties file", ex); } } } }
From source file:com.bstek.dorado.console.system.log.file.FileReaderController.java
/** * ?//from w w w.j av a 2s.com * * @return * @throws IOException */ public static String getLogDirectoryPath() throws IOException { String runMode = Configure.getString("core.runMode"); String fileName = "console.properties"; if (StringUtils.isNotEmpty(runMode)) { fileName = "configure-" + runMode + ".properties"; } String log_directory_path = Configure.getString(Constants.LOG_DIRECTORY_PATH); if (StringUtils.isEmpty(log_directory_path)) { // ResourceLoader ResourceLoader resourceLoader = new ServletContextResourceLoader( DoradoContext.getAttachedServletContext()); String path = ResourceUtils.concatPath(Configure.getString("core.doradoHome"), fileName); Resource resource = resourceLoader.getResource(path); InputStream in = resource.getInputStream(); if (in != null) { Properties properties = new Properties(); try { properties.load(in); } finally { in.close(); } log_directory_path = (String) properties.get(Constants.LOG_DIRECTORY_PATH); } } return log_directory_path; }
From source file:com.alibaba.rocketmq.filtersrv.FiltersrvStartup.java
public static FiltersrvController createController(String[] args) { System.setProperty(RemotingCommand.RemotingVersionKey, Integer.toString(MQVersion.CurrentVersion)); // Socket???//from w w w . j a v a 2 s . c om if (null == System.getProperty(NettySystemConfig.SystemPropertySocketSndbufSize)) { NettySystemConfig.SocketSndbufSize = 65535; } // Socket? if (null == System.getProperty(NettySystemConfig.SystemPropertySocketRcvbufSize)) { NettySystemConfig.SocketRcvbufSize = 1024; } try { // ? Options options = ServerUtil.buildCommandlineOptions(new Options()); final CommandLine commandLine = ServerUtil.parseCmdLine("mqfiltersrv", args, buildCommandlineOptions(options), new PosixParser()); if (null == commandLine) { System.exit(-1); return null; } // ?? final FiltersrvConfig filtersrvConfig = new FiltersrvConfig(); final NettyServerConfig nettyServerConfig = new NettyServerConfig(); if (commandLine.hasOption('c')) { String file = commandLine.getOptionValue('c'); if (file != null) { InputStream in = new BufferedInputStream(new FileInputStream(file)); Properties properties = new Properties(); properties.load(in); MixAll.properties2Object(properties, filtersrvConfig); System.out.println("load config properties file OK, " + file); in.close(); String port = properties.getProperty("listenPort"); if (port != null) { filtersrvConfig.setConnectWhichBroker(String.format("127.0.0.1:%s", port)); } } } // 0??? nettyServerConfig.setListenPort(0); nettyServerConfig.setServerAsyncSemaphoreValue(filtersrvConfig.getFsServerAsyncSemaphoreValue()); nettyServerConfig .setServerCallbackExecutorThreads(filtersrvConfig.getFsServerCallbackExecutorThreads()); nettyServerConfig.setServerWorkerThreads(filtersrvConfig.getFsServerWorkerThreads()); // ?? if (commandLine.hasOption('p')) { MixAll.printObjectProperties(null, filtersrvConfig); MixAll.printObjectProperties(null, nettyServerConfig); System.exit(0); } MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), filtersrvConfig); if (null == filtersrvConfig.getRocketmqHome()) { System.out.println("Please set the " + MixAll.ROCKETMQ_HOME_ENV + " variable in your environment to match the location of the RocketMQ installation"); System.exit(-2); } // ?Logback LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); configurator.doConfigure(filtersrvConfig.getRocketmqHome() + "/conf/logback_filtersrv.xml"); log = LoggerFactory.getLogger(LoggerName.FiltersrvLoggerName); // ?? final FiltersrvController controller = new FiltersrvController(filtersrvConfig, nettyServerConfig); boolean initResult = controller.initialize(); if (!initResult) { controller.shutdown(); System.exit(-3); } Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { private volatile boolean hasShutdown = false; private AtomicInteger shutdownTimes = new AtomicInteger(0); @Override public void run() { synchronized (this) { log.info("shutdown hook was invoked, " + this.shutdownTimes.incrementAndGet()); if (!this.hasShutdown) { this.hasShutdown = true; long begineTime = System.currentTimeMillis(); controller.shutdown(); long consumingTimeTotal = System.currentTimeMillis() - begineTime; log.info("shutdown hook over, consuming time total(ms): " + consumingTimeTotal); } } } }, "ShutdownHook")); return controller; } catch (Throwable e) { e.printStackTrace(); System.exit(-1); } return null; }
From source file:com.amazonaws.mturk.cmd.AbstractCmd.java
protected static Properties loadProperties(String fileName) throws IOException { // Read properties file. Properties props = new Properties(); props.load(new java.io.FileInputStream(new java.io.File(fileName))); return props; }
From source file:org.gtri.fhir.api.vistaex.rest.service.util.VistaUtil.java
public static Properties getProperties() { Properties properties = null; try {/* w w w .j a v a2 s.com*/ InputStream fis = getFileInputStreamFromClassPath(PROPERTIES_FILE); properties = new Properties(); properties.load(fis); } catch (FileNotFoundException fnfe) { fnfe.printStackTrace(); properties = null; } catch (IOException ioe) { ioe.printStackTrace(); properties = null; } return properties; }
From source file:org.processbase.ui.core.Constants.java
public static Properties getJournalProperties(String domain) { if (StringUtils.isEmpty(domain)) domain = "default"; if (journalProperties.containsKey(domain)) return journalProperties.get(domain); String userHomeDir = BonitaConstants.getBonitaHomeFolder(); File file = new File(userHomeDir + "/server/" + domain + "/conf/bonita-journal.properties"); FileInputStream in = null;//from ww w.j ava2 s . c om try { in = new FileInputStream(file); Properties properties = new Properties(); properties.load(in); journalProperties.put(domain, properties); return properties; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } return null; }
From source file:VoldemortStatusPage.java
private static Properties lookupProperties(String fileName) throws IOException, FileNotFoundException { Properties p = new Properties(); File propertyFile = new File(fileName); FileInputStream is = null;/*from www . java 2 s.c o m*/ is = new FileInputStream(propertyFile); p.load(is); is.close(); return p; }
From source file:keel.Algorithms.Genetic_Rule_Learning.Bojarczuk_GP.Main.java
/** * <p>/*from ww w. j a va 2 s . c om*/ * 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.freitas.FreitasAlgorithm"); 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.freitas.FreitasSyntaxTreeSpecies"); algConf.addProperty("process.evaluator[@type]", "net.sourceforge.jclec.problem.classification.freitas.FreitasEvaluator"); 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.freitas.FreitasCrossover"); algConf.addProperty("process.copy-prob", Double.parseDouble(props.getProperty("copy-prob"))); algConf.addProperty("process.listener[@type]", "net.sourceforge.jclec.problem.classification.freitas.KeelFreitasPopulationReport"); 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:com.momab.dstool.DSTool.java
static String getVersionString() { Properties prop = new Properties(); InputStream in = DSTool.class.getResourceAsStream("version.properties"); try {//from www. j a v a 2 s.c o m prop.load(in); in.close(); } catch (IOException e) { return "Could not read version.properties"; } return prop.getProperty("version"); }
From source file:main.java.com.aosa.util.AOSAReadProperties.java
/** * Description<code>Properties</code> <br> * By mutou at 2012-1-12 ?05:58:16 <br> * boolean <br>/*from w ww .j ava2s . c o m*/ * @param profileName * Properties ??ClassPath * @param key * ?? * @param value * ? value * @return * @throws */ public static boolean WriteValue(String profileName, String key, String value) { boolean isWrite = false; Properties properties = new Properties(); InputStream input = AOSAReadProperties.class.getClassLoader().getResourceAsStream(profileName); try { properties.load(input); properties.setProperty(key, value); URL prourl = AOSAReadProperties.class.getClassLoader().getResource(profileName); String filepath = prourl.getFile(); FileOutputStream fileOutputStream = new FileOutputStream(filepath); properties.store(fileOutputStream, "Custum shutDownTime config : conf.properties"); fileOutputStream.flush(); fileOutputStream.close(); isWrite = true; } catch (FileNotFoundException e) { logger.debug("Properties"); throw new AOSARuntimeException("Properties", e); } catch (IOException e) { logger.debug("PropertiesIO"); throw new AOSARuntimeException("PropertiesIO", e); } finally { if (input != null) { try { input.close(); } catch (IOException e) { logger.debug("IO?"); throw new AOSARuntimeException("IO?", e); } } } return isWrite; }