List of usage examples for java.util Properties stringPropertyNames
public Set<String> stringPropertyNames()
From source file:com.evolveum.midpoint.repo.sql.SqlRepositoryServiceImpl.java
private void readDetailsFromConnection(RepositoryDiag diag, final SqlRepositoryConfiguration config) { final List<LabeledString> details = diag.getAdditionalDetails(); Session session = getSessionFactory().openSession(); try {//from www.j av a 2s. c om session.beginTransaction(); session.doWork(new Work() { @Override public void execute(Connection connection) throws SQLException { details.add(new LabeledString(DETAILS_TRANSACTION_ISOLATION, getTransactionIsolation(connection, config))); Properties info = connection.getClientInfo(); if (info == null) { return; } for (String name : info.stringPropertyNames()) { details.add(new LabeledString(DETAILS_CLIENT_INFO + name, info.getProperty(name))); } } }); session.getTransaction().commit(); if (!(getSessionFactory() instanceof SessionFactoryImpl)) { return; } SessionFactoryImpl factory = (SessionFactoryImpl) getSessionFactory(); // we try to override configuration which was read from sql repo configuration with // real configuration from session factory String dialect = factory.getDialect() != null ? factory.getDialect().getClass().getName() : null; details.add(new LabeledString(DETAILS_HIBERNATE_DIALECT, dialect)); } catch (Throwable th) { //nowhere to report error (no operation result available) session.getTransaction().rollback(); } finally { cleanupSessionAndResult(session, null); } }
From source file:ch.oakmountain.tpa.parser.TpaParser.java
public TpaParser(Properties applicationProps, String fileName) throws IOException { this.applicationProps = applicationProps; Set<String> stringPropertyNames = applicationProps.stringPropertyNames(); for (tpaProps tpaProp : tpaProps.values()) { if (!stringPropertyNames.contains(tpaProp.name())) { throw new IllegalArgumentException("Property \"" + tpaProp.name() + "\" has not been set in the the tpa configuration properties"); }/*from w w w . j a v a 2s. c o m*/ } FileInputStream fin = new FileInputStream(fileName); wb = new HSSFWorkbook(fin); mapping = readNodeAbbrMapping(wb); timestyle = wb.createCellStyle(); DataFormat df = wb.createDataFormat(); timestyle.setDataFormat(df.getFormat("hh:mm:ss")); }
From source file:org.springframework.xd.dirt.plugins.spark.streaming.SparkStreamingPlugin.java
/** * Setup {@link org.apache.spark.SparkConf} for the given spark configuration properties. * * @param masterURL the spark cluster master URL * @param sparkConfigs the spark configuration properties * @return SparkConf for this spark streaming module *//*from w ww .j a v a 2 s . com*/ private SparkConf setupSparkConf(Module module, String masterURL, Properties sparkConfigs) { SparkConf sparkConf = new SparkConf() // Set spark UI port to random available port to support multiple spark modules on the same host. .set("spark.ui.port", String.valueOf(SocketUtils.findAvailableTcpPort())) // Set the cores max so that multiple (at least a few) spark modules can be deployed on the same host. .set("spark.cores.max", "3").setMaster(masterURL) .setAppName(module.getDescriptor().getGroup() + "-" + module.getDescriptor().getModuleLabel()); if (sparkConfigs != null) { for (String property : sparkConfigs.stringPropertyNames()) { sparkConf.set(property, sparkConfigs.getProperty(property)); } } List<String> sparkJars = new ArrayList<>(); // Add jars from spark.jars (if any) set from spark module. try { String jarsFromConf = sparkConf.get("spark.jars"); if (StringUtils.hasText(jarsFromConf)) { sparkJars.addAll(Arrays.asList(jarsFromConf.split("\\s*,\\s*"))); } } catch (NoSuchElementException e) { // should ignore } sparkJars.addAll(getApplicationJars(module)); sparkConf.setJars(sparkJars.toArray(new String[sparkJars.size()])); return sparkConf; }
From source file:org.wso2.carbon.ui.valve.XSSValve.java
private void buildScriptPatterns() { patternList = new ArrayList<Pattern>(Arrays.asList(patterns)); if (patterPath != null && !patterPath.isEmpty()) { InputStream inStream = null; File xssPatternConfigFile = new File(patterPath); Properties properties = new Properties(); if (xssPatternConfigFile.exists()) { try { inStream = new FileInputStream(xssPatternConfigFile); properties.load(inStream); } catch (FileNotFoundException e) { log.error("Can not load xssPatternConfig properties file ", e); } catch (IOException e) { log.error("Can not load xssPatternConfigFile properties file ", e); } finally { if (inStream != null) { try { inStream.close(); } catch (IOException e) { log.error("Error while closing stream ", e); }/*from w ww . j a va2s . co m*/ } } } if (!properties.isEmpty()) { for (String key : properties.stringPropertyNames()) { String value = properties.getProperty(key); patternList.add(Pattern.compile(value, Pattern.CASE_INSENSITIVE)); } } } }
From source file:edu.snu.leader.hierarchy.simple.DefaultReporter.java
/** * Initializes this reporter//from w w w. jav a 2 s.c om * * @param simState The simulation state * @see edu.snu.leader.hierarchy.simple.Reporter#initialize(edu.snu.leader.hierarchy.simple.SimulationState) */ @Override public void initialize(SimulationState simState) { _LOG.trace("Entering initialize( state )"); // Store the simulatino state _simState = simState; // Grab the properties Properties props = simState.getProps(); // Load the statistics filename String statsFile = props.getProperty(_STATS_FILE_KEY); Validate.notEmpty(statsFile, "Statistics file may not be empty"); // Create the statistics writer try { _writer = new PrintWriter(new BufferedWriter(new FileWriter(statsFile))); } catch (IOException ioe) { _LOG.error("Unable to open stats file [" + statsFile + "]", ioe); throw new RuntimeException("Unable to open stats file [" + statsFile + "]", ioe); } // Log the system properties to the stats file for future reference _writer.println("# Started: " + (new Date())); _writer.println(_STATS_SPACER); _writer.println("# Simulation properties"); _writer.println(_STATS_SPACER); List<String> keyList = new ArrayList<String>(props.stringPropertyNames()); Collections.sort(keyList); Iterator<String> iter = keyList.iterator(); while (iter.hasNext()) { String key = iter.next(); String value = props.getProperty(key); _writer.println("# " + key + " = " + value); } _writer.println(_STATS_SPACER); _writer.println(); _LOG.trace("Leaving initialize( state )"); }
From source file:org.apache.nifi.documentation.DocGeneratorTest.java
private NiFiProperties loadSpecifiedProperties(final String propertiesFile, final String key, final String value) { String file = DocGeneratorTest.class.getResource(propertiesFile).getFile(); System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, file); final Properties props = new Properties(); InputStream inStream = null;/*from www .j av a 2 s . co m*/ try { inStream = new BufferedInputStream(new FileInputStream(file)); props.load(inStream); } catch (final Exception ex) { throw new RuntimeException("Cannot load properties file due to " + ex.getLocalizedMessage(), ex); } finally { if (null != inStream) { try { inStream.close(); } catch (final Exception ex) { /** * do nothing * */ } } } if (key != null && value != null) { props.setProperty(key, value); } return new NiFiProperties() { @Override public String getProperty(String key) { return props.getProperty(key); } @Override public Set<String> getPropertyKeys() { return props.stringPropertyNames(); } }; }
From source file:es.ehu.si.ixa.qwn.ppv.CLI.java
public final void compileGraph() throws IOException { String kb = parsedArguments.getString("kb"); String ukb = parsedArguments.getString("ukbPath"); // normal case: single graph is created if (!kb.equals("all")) { ukb_compile(ukb, kb);/*from ww w . ja v a 2 s .c om*/ System.out.println("new graph generated: " + kb + ".bin"); } // compile all graphs in the distribution else { System.out.println("Default behavior: all the graphs in the qwn-ppv distribution will be compiled"); Properties AvailableGraphs = new Properties(); try { AvailableGraphs .load(Thread.currentThread().getContextClassLoader().getResourceAsStream("graphs.txt")); } catch (IOException ioe) { ioe.printStackTrace(); } for (String key : AvailableGraphs.stringPropertyNames()) { String jarlocation = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); String location = jarlocation.substring(0, jarlocation.lastIndexOf("/")); String destKBPath = location + File.separator + "graphs" + File.separator + (String) AvailableGraphs.get(key); try { GZIPInputStream kbExtract = new GZIPInputStream(this.getClass().getClassLoader() .getResourceAsStream("graphs/" + (String) AvailableGraphs.get(key) + ".txt.gz")); File KBPath = new File(location + File.separator + "graphs"); KBPath.mkdirs(); OutputStream kbDestination = new FileOutputStream(destKBPath + ".txt"); IOUtils.copy(kbExtract, kbDestination); kbExtract.close(); kbDestination.close(); } catch (IOException ioe) { ioe.printStackTrace(); } ukb_compile(ukb, destKBPath + ".txt"); } } }
From source file:de.tudarmstadt.lt.lm.lucenebased.CountingStringLM.java
public CountingStringLM(int order, File index_dir) { _order = order;// w w w. j a v a 2s . c o m try { LOG.info("Loading index from or creating index in '{}'.", index_dir.getAbsolutePath()); File index_dir_vocab = new File(index_dir, "vocab"); File index_dir_ngram = new File(index_dir, "ngram"); _fixed = true; Directory directory = MMapDirectory.open(index_dir_ngram); // directory = new RAMDirectory(directory, IOContext.DEFAULT); _reader_ngram = DirectoryReader.open(directory); _searcher_ngram = new IndexSearcher(_reader_ngram); directory = MMapDirectory.open(index_dir_vocab); // directory = new RAMDirectory(directory, IOContext.DEFAULT); _reader_vocab = DirectoryReader.open(directory); _searcher_vocab = new IndexSearcher(_reader_vocab); LOG.info("Computing number of ngram occurrences."); File sumfile = new File(index_dir, "__sum_ngrams__"); try { InputStream in = new FileInputStream(sumfile); Properties p = new Properties(); p.load(in); in.close(); int max_n = Math.max(_order, Integer.parseInt(p.getProperty("max_n"))); if (max_n < order) LOG.error("max_n={} in {} is smaller than the order of the language model ({}).", max_n, sumfile, order); int max_c = Integer.parseInt(p.getProperty("max_c")); _N = new double[max_n + 1][max_c]; _sum_ngrams = new double[max_n + 1]; for (String name : p.stringPropertyNames()) { if (name.startsWith("n")) { int n = Integer.parseInt(name.substring(1, name.length())); String[] v = p.getProperty(name).split(","); for (int i = 0; i < v.length; i++) { _N[n][i] = Double.parseDouble(v[i]); } } else if (name.startsWith("s")) { int n = Integer.parseInt(name.substring(1, name.length())); _sum_ngrams[n] = Double.parseDouble(p.getProperty(name)); } } } catch (Exception e) { LOG.error("Could not read ngram sum file '{}'.", sumfile, e); _N = new double[order + 1][6]; _sum_ngrams = new double[order + 1]; } _num_ngrams = new double[_N.length][4]; long sum = 0; for (int n = 0; n < _N.length; n++) { for (int i = 0; i < 3; i++) _num_ngrams[n][i] = _N[n][i]; for (int i = 3; i < _N[n].length; i++) _num_ngrams[n][3] += _N[n][i]; sum += _num_ngrams[n][0]; } LOG.info("Number of Ngrams {}.", _searcher_ngram.collectionStatistics("ngram").docCount()); LOG.info("Number of Ngrams {}.", sum); LOG.info("Vocabulary Size {}.", _searcher_vocab.collectionStatistics("word").docCount()); } catch (IOException e) { LOG.error("Could not open lucene index: Dir={}; Dir exists={}; ", index_dir, index_dir.exists() && index_dir.isDirectory(), e); } }
From source file:org.metaeffekt.dcc.commons.spring.xml.DCCConfigurationBeanDefinitionParser.java
private String replaceVariables(BeanDefinitionRegistry registry, String string) { if (string != null && string.contains("${")) { final Properties properties = ImportBeanDefinitionParser.getParsingContextProperties(registry); final Set<String> names = properties.stringPropertyNames(); for (String key : names) { string = string.replaceAll("\\$\\{" + key + "\\}", properties.getProperty(key)); }//from w w w . ja v a 2 s . co m } return string; }
From source file:org.ow2.proactive.scheduler.authentication.ManageUsers.java
/** * Update the accounts in the login and config files * * @throws ManageUsersException/* w ww . j a v a 2 s . c o m*/ */ private static void updateAccounts(final PublicKey pubKey, final UserInfo userInfo, final String loginFilePath, final String groupFilePath, final Action action, final String sourceLoginFile, final String sourceGroupFile) throws ManageUsersException { try { Properties destinationLoginProps = new Properties(); try (InputStreamReader stream = new InputStreamReader(new FileInputStream(loginFilePath))) { destinationLoginProps.load(stream); } catch (Exception e) { exitWithErrorMessage("could not read login file : " + loginFilePath, null, e); } Multimap<String, String> destinationGroupsMap = loadGroups(groupFilePath); Properties sourceLoginProps = new Properties(); if (sourceLoginFile != null) { try (InputStreamReader stream = new InputStreamReader(new FileInputStream(sourceLoginFile))) { sourceLoginProps.load(stream); } catch (Exception e) { exitWithErrorMessage("could not read source login file : " + sourceLoginFile, null, e); } } else if (userInfo != null) { if (userInfo.getPassword() == null) { // password can be null in case of account deletion sourceLoginProps.put(userInfo.getLogin(), ""); } else { sourceLoginProps.put(userInfo.getLogin(), userInfo.getPassword()); } } Multimap<String, String> sourceGroupsMap = null; if (sourceGroupFile != null) { sourceGroupsMap = loadGroups(sourceGroupFile); } else { sourceGroupsMap = TreeMultimap.create(); if (userInfo != null && !userInfo.getGroups().isEmpty()) { for (String group : userInfo.getGroups()) { sourceGroupsMap.put(userInfo.getLogin(), group); } } } Collection<String> sourceLoginNames = sourceLoginProps.stringPropertyNames(); if (sourceLoginNames.isEmpty()) { sourceLoginNames = sourceGroupsMap.keySet(); } boolean bulkMode = sourceLoginNames.size() > 1; for (String user : sourceLoginNames) { UserInfo sourceUserInfo = new UserInfo(); sourceUserInfo.setLogin(user); sourceUserInfo.setPassword((String) sourceLoginProps.get(user)); if (sourceGroupsMap.containsKey(user)) { sourceUserInfo.setGroups(sourceGroupsMap.get(user)); } switch (action) { case CREATE: createAccount(pubKey, sourceUserInfo, loginFilePath, groupFilePath, destinationLoginProps, destinationGroupsMap); break; case UPDATE: updateAccount(pubKey, sourceUserInfo, loginFilePath, destinationLoginProps, destinationGroupsMap, bulkMode); break; case DELETE: deleteAccount(sourceUserInfo, loginFilePath, groupFilePath, destinationLoginProps, destinationGroupsMap); break; } } storeLoginFile(loginFilePath, destinationLoginProps); storeGroups(groupFilePath, destinationGroupsMap); } catch (Throwable t) { exitWithErrorMessage("Unexpected error", null, t); } }