List of usage examples for java.util Properties get
@Override
public Object get(Object key)
From source file:Main.java
/** * Return serializable data, the format of these data is placed like the following format * ${key}=${value}/*from ww w . j a v a 2s. c om*/ * * @param properties Properties instance * @return serializable data * @throws java.io.UnsupportedEncodingException * if errors occure during text converted to UTF-8 encoding */ public static byte[] getSerializablePropertiesData(Properties properties) throws UnsupportedEncodingException { Set keySet = properties.keySet(); TreeSet keys = new TreeSet(keySet); Iterator it = keys.iterator(); StringBuffer bf = new StringBuffer(); while (it.hasNext()) { String item = (String) it.next(); String resourceValue = (String) properties.get(item); bf.append(item); bf.append("="); bf.append(resourceValue); bf.append("\n"); } return bf.toString().getBytes("UTF-8"); }
From source file:de.hypoport.ep2.support.configuration.properties.PropertiesLoader.java
static void replacePropertyPlaceHolder(Properties properties) { Enumeration<?> keyEnum = properties.propertyNames(); while (keyEnum.hasMoreElements()) { String key = (String) keyEnum.nextElement(); Object value = properties.get(key); if (value != null && value instanceof String) { String valueString = (String) value; valueString = replacePropertyPlaceHolder(valueString, properties); properties.put(key, valueString); }//from w w w.j a v a2 s. c o m } }
From source file:com.hightail.metrics.reporter.NewRelicReporterFactory.java
private static NewRelicReporter buildNewRelicHttpV1Instance(Properties properties) throws CannotCreateInstanceException { List<String> errorMsgs = new ArrayList<String>(); if (!properties.containsKey(NewRelicConstants.METRIC_REGISTRY) || properties.get(NewRelicConstants.METRIC_REGISTRY) == null) { errorMsgs.add(NewRelicConstants.METRIC_REGISTRY + " is not provided"); }//from w w w . j a va 2s .com if (!properties.containsKey(NewRelicConstants.LICENSE_KEY) || StringUtils.isBlank(properties.getProperty(NewRelicConstants.LICENSE_KEY))) { errorMsgs.add(NewRelicConstants.LICENSE_KEY + " is not provided"); } if (!properties.containsKey(NewRelicConstants.COMPONENT_NAME) || StringUtils.isBlank(properties.getProperty(NewRelicConstants.COMPONENT_NAME))) { errorMsgs.add(NewRelicConstants.COMPONENT_NAME + " is not provided"); } if (!properties.containsKey(NewRelicConstants.APP_ID) || StringUtils.isBlank(properties.getProperty(NewRelicConstants.APP_ID))) { errorMsgs.add(NewRelicConstants.APP_ID + " is not provided"); } if (!errorMsgs.isEmpty()) { logger.error("Cannot instantiate New Relic Reporter because mandatory attributes are not provided: " + errorMsgs.toString()); throw new CannotCreateInstanceException(errorMsgs.toString()); } MetricRegistry registry = (MetricRegistry) properties.get(NewRelicConstants.METRIC_REGISTRY); String licenseKey = properties.getProperty(NewRelicConstants.LICENSE_KEY); String componentName = properties.getProperty(NewRelicConstants.COMPONENT_NAME); String appId = properties.getProperty(NewRelicConstants.APP_ID); String prefix = (properties.containsKey(NewRelicConstants.PREFIX)) ? properties.getProperty(NewRelicConstants.PREFIX) : NewRelicConstants.DEFAULT_PREFIX; TimeUnit rateUnit = (properties.containsKey(NewRelicConstants.RATE_UNIT)) ? (TimeUnit) properties.get(NewRelicConstants.RATE_UNIT) : NewRelicConstants.DEFAULT_RATE_UNIT; TimeUnit durationUnit = (properties.containsKey(NewRelicConstants.DURATION_UNIT)) ? (TimeUnit) properties.get(NewRelicConstants.DURATION_UNIT) : NewRelicConstants.DEFAULT_DURATION_UNIT; MetricFilter filter = (properties.containsKey(NewRelicConstants.METRIC_FILTER)) ? (MetricFilter) properties.get(NewRelicConstants.METRIC_FILTER) : NewRelicConstants.DEFAULT_METRIC_FILTER; NewRelic newRelic = new NewRelic(NewRelicConstants.DEFAULT_URL, licenseKey, componentName, appId); return NewRelicHTTPv1Reporter.forRegistry(registry).prefixedWith(prefix).convertRatesTo(rateUnit) .convertDurationsTo(durationUnit).filter(filter).build(newRelic); }
From source file:net.itransformers.bgpPeeringMap.BgpPeeringMap.java
private static Map<String, String> loadProperties(File file) throws IOException { Properties props = new Properties(); props.load(new FileInputStream(file)); HashMap<String, String> settings = new HashMap<String, String>(); for (Object key : props.keySet()) { settings.put((String) key, (String) props.get(key)); }//ww w. j av a2 s .c o m return settings; }
From source file:ddf.security.common.util.PropertiesLoader.java
@SuppressWarnings("unchecked") public static <K, V> Map<K, V> toMap(Properties properties) { if (properties != null) { Set<K> keySet = (Set<K>) properties.keySet(); Map<K, V> map = new HashMap<K, V>(keySet.size() * 2); for (K obj : keySet) { map.put(obj, (V) properties.get(obj)); }/*from ww w . j a va 2s . c o m*/ return map; } return new HashMap<K, V>(); }
From source file:com.eviware.soapui.monitor.PropertySupport.java
public static void applySystemProperties(Object target, String scope, ModelItem modelItem) { PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(target); DefaultPropertyExpansionContext context = new DefaultPropertyExpansionContext(modelItem); Properties properties = System.getProperties(); for (PropertyDescriptor descriptor : descriptors) { String name = descriptor.getName(); String key = scope + "." + name; if (PropertyUtils.isWriteable(target, name) && properties.containsKey(key)) { try { String value = context.expand(String.valueOf(properties.get(key))); BeanUtils.setProperty(target, name, value); SoapUI.log.info("Set property [" + name + "] to [" + value + "] in scope [" + scope + "]"); } catch (Throwable e) { SoapUI.logError(e);/*from w w w . ja va 2 s. c o m*/ } } } }
From source file:com.bstek.dorado.console.system.log.file.FileReaderController.java
/** * ?/* www . j av a2s. c o m*/ * * @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.jslsolucoes.tagria.lib.util.TagUtil.java
public static String getInitParam(TagriaConfigParameter tagriaConfigParameter) { InputStream props = TagUtil.class.getResourceAsStream("/tagrialib.properties"); if (props == null) { return tagriaConfigParameter.getDefaultValue(); } else {/*from w w w . jav a2s. co m*/ try { Properties properties = new Properties(); properties.load(props); String value = (String) properties.get(tagriaConfigParameter.getName()); if (value == null) return tagriaConfigParameter.getDefaultValue(); return value; } catch (IOException exception) { logger.error("Could not load tagrialib.properties", exception); } } return null; }
From source file:com.aw.core.business.AWContext.java
public static void initBuildInfo() { buildNumber = "<Undefined>"; java.util.Properties props = new java.util.Properties(); // java.net.URL url = ClassLoader.getSystemResource("version.properties"); Resource r = new ClassPathResource("version.properties"); try {/*from w w w . j a va 2 s . c o m*/ props.load(r.getInputStream()); buildNumber = (String) props.get("version"); } catch (Throwable e) { logger.warn("Error loading project version Info", e); e.printStackTrace(); } }
From source file:io.uengine.util.StringUtils.java
/** * Properties? key value ? ./*w w w.j a v a2 s . c om*/ * * @param properties Properties * @return key value ? */ public static String propertiesToString(Properties properties) { StringWriter writer = new StringWriter(); PrintWriter out = new PrintWriter(writer); Set<Object> keys = properties.keySet(); for (Object key : keys) { out.println(key + "=" + properties.get(key)); } return writer.getBuffer().toString(); }