List of usage examples for java.util Properties getProperty
public String getProperty(String key)
From source file:com.googlecode.msidor.springframework.integration.history.MessageHistoryParser.java
/** * Parse message history generated by spring integration and produce output with components names and components processing times * //from w w w . j a v a 2 s. c o m * @param mh message headers to be parsed * @return output with components names and components processing times */ public static String parse(MessageHeaders mh) { StringBuilder sb = new StringBuilder(); //get message history MessageHistory history = mh.get(MessageHistory.HEADER_NAME, MessageHistory.class); String[] names = new String[history.size()]; long[] times = new long[history.size()]; //go thought all history entries Iterator<Properties> historyIterator = history.iterator(); int i = 0; while (historyIterator.hasNext()) { Properties gatewayHistory = historyIterator.next(); String name = gatewayHistory.getProperty("name"); String historyTimestampStr = gatewayHistory.getProperty("timestamp"); Long historyTimestamp = Long.parseLong(historyTimestampStr); names[i] = name; times[i++] = historyTimestamp; } //calculates the time deltas between components final long lastTimestamp = mh.getTimestamp(); for (int j = 0; j < names.length; j++) { if (j > 0) { sb.append("; "); } if (j + 1 < names.length) sb.append(names[j]).append("=").append(times[j + 1] - times[j]); else sb.append(names[j]).append("=").append(lastTimestamp - times[j]); } if (sb.length() > 0) { sb.append("; "); } sb.append("total=").append(lastTimestamp - times[0]); return sb.toString(); }
From source file:com.sosee.util.PropertyUtil.java
public static String readValue(String key) { Properties props = new Properties(); try {/*ww w .j a va 2 s .c om*/ InputStream in = new BufferedInputStream(new FileInputStream(getFilePath())); props.load(in); String value = props.getProperty(key); return value == null ? "" : value; } catch (Exception e) { return ""; } }
From source file:com.germinus.easyconf.ClassParameter.java
public static Object getNewInstance(Properties props, String propertyName) throws ClassNotFoundException, IllegalAccessException, InstantiationException { String className = props.getProperty(propertyName); log.info("Returning " + className + " class instance."); return ClasspathUtil.locateClass(className).newInstance(); }
From source file:com.cognifide.qa.bb.utils.PropertyUtils.java
private static void overrideTimeouts(Properties properties) { int big = Integer.parseInt(properties.getProperty(ConfigKeys.TIMEOUTS_BIG)); int medium = Integer.parseInt(properties.getProperty(ConfigKeys.TIMEOUTS_MEDIUM)); int small = Integer.parseInt(properties.getProperty(ConfigKeys.TIMEOUTS_SMALL)); int minimal = Integer.parseInt(properties.getProperty(ConfigKeys.TIMEOUTS_MINIMAL)); new Timeouts(big, medium, small, minimal); }
From source file:com.moz.fiji.hive.FijiTableInfo.java
/** * Gets the URI from the passed in properties. * @param properties for the job.//from w ww. j av a 2 s.com * @return FijiURI extracted from the passed in properties. */ public static FijiURI getURIFromProperties(Properties properties) { String fijiURIString = properties.getProperty(FIJI_TABLE_URI); //TODO Pretty exceptions for URI parser issues. FijiURI fijiURI = FijiURI.newBuilder(fijiURIString).build(); //TODO Ensure that this URI has a table component. return fijiURI; }
From source file:io.seldon.semvec.SemanticVectorsStore.java
public static void initialise(Properties props) { SemanticVectorsStore.baseDirectory = props.getProperty("io.seldon.labs.semvec.basedir"); if (SemanticVectorsStore.baseDirectory == null) { logger.warn("No base directory for semantic vectors specified"); } else {//from w ww . ja v a 2s. c om String clientsToPreload = props.getProperty("io.seldon.labs.semvec.preload"); if (!StringUtils.isEmpty(clientsToPreload)) { String client[] = clientsToPreload.split(","); for (int i = 0; i < client.length; i++) { String prefixStr = props.getProperty("io.seldon.labs.semvec.preload.prefix." + client[i]); if (prefixStr == null) prefixStr = "text"; if (prefixStr != null) { String prefix[] = prefixStr.split(","); for (int j = 0; j < prefix.length; j++) { logger.info("Preloading semantic vectors store for client " + client[i] + " with prefix " + prefix[j] + "..."); SemVectorsPeer svPeer = get(client[i], prefix[j]); if (svPeer == null) { // logger.error("Failed to preload store for client "+client[i]+" with prefix "+prefix[j]); final String message = "Failed to preload store for client " + client[i] + " with prefix " + prefix[j]; logger.error(message, new Exception(message)); } else logger.info("Preloaded semantic vectors store for client " + client[i] + " with prefix " + prefix[j]); } } } } } }
From source file:com.homeadvisor.kafdrop.util.JmxUtils.java
public static int getJmxPort(final Environment environment) { Optional<Integer> jmxPort = Optional.empty(); final Properties managementProperties = Agent.getManagementProperties(); if (managementProperties != null) { final String portProperty = managementProperties.getProperty(JMX_PORT_PROPERTY); if (portProperty != null) { final Optional<Integer> port = Optional.ofNullable(Ints.tryParse(portProperty)); jmxPort = port;/*ww w . ja va 2 s . c o m*/ } } return jmxPort.orElse(0); }
From source file:cpcc.core.utils.VersionUtils.java
/** * @param moduleName the module name/*from w w w . j a v a 2 s .c om*/ * @return the module name and module version. */ public static String getModuleVersion(String moduleName, String propertyFile) { try (InputStream stream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(propertyFile)) { Properties props = new Properties(); props.load(stream); String version = props.getProperty("module.version"); if (StringUtils.isEmpty(version)) { throw new IllegalArgumentException(String.format(VERSION_NOT_SET, propertyFile)); } if (version.startsWith("${")) { throw new IllegalArgumentException(String.format(RESOURCE_FILTERING_FAILED, propertyFile)); } if (version.endsWith("SNAPSHOT")) { version += '-' + System.currentTimeMillis(); } return moduleName + '/' + version; } catch (IOException e) { throw new IllegalArgumentException(String.format(RESOURCE_NOT_FOUND, propertyFile)); } }
From source file:com.googlecode.fascinator.DBIntegrationTestSuite.java
@AfterClass public static void tearDown() throws IOException, BeansException, SQLException { Properties prop = new Properties(); prop.load(new FileInputStream("src/test/resources/database.properties")); String dbString = prop.getProperty("jdbc.databaseurl"); try {/* w w w. j a va2 s .co m*/ DriverManager.getConnection(dbString + ";shutdown=true"); } catch (SQLNonTransientConnectionException exception) { } catch (SQLException e) { } FileUtils.deleteDirectory(new File("target/database")); }
From source file:com.dragoniade.encrypt.EncryptionHelper.java
public static void decrypt(Properties p, String seedKey, String key) { String value = p.getProperty(key); String seed = p.getProperty(seedKey, seedKey); if (value == null || value.length() == 0) { return;// w w w. j av a 2s . c o m } int index = value.indexOf('{'); switch (index) { case -1: return; case 0: { String toDecode = value.substring(1, value.length() - 1); String decryptStr; try { decryptStr = new String(Base64.decode(toDecode), "UTF-16"); } catch (UnsupportedEncodingException e1) { decryptStr = new String(Base64.decode(toDecode)); } p.setProperty(key, decryptStr); return; } default: String toDecode = value.substring(index + 1, value.length() - 1); String algorithm = value.substring(0, index); byte[] decryptStr = Base64.decode(toDecode); Cipher cipher = getDecrypter(seed, algorithm); String decoded; try { byte[] result = cipher.doFinal(decryptStr); try { decoded = new String(result, "UTF-16"); } catch (UnsupportedEncodingException e1) { decoded = new String(result); } } catch (Exception e) { decoded = ""; } p.setProperty(key, decoded); } }