List of usage examples for java.util Properties entrySet
@Override
public Set<Map.Entry<Object, Object>> entrySet()
From source file:io.cloudslang.lang.commons.services.impl.UserConfigurationServiceImpl.java
@Override public void loadUserProperties() throws IOException { String appHome = System.getProperty("app.home"); String propertyFilePath = appHome + File.separator + USER_CONFIG_FILEPATH; File propertyFile = new File(propertyFilePath); Properties rawProperties = new Properties(); if (propertyFile.isFile()) { try (InputStream propertiesStream = new FileInputStream(propertyFilePath)) { rawProperties.load(propertiesStream); }//from ww w . j a va2 s .c om } Set<Map.Entry<Object, Object>> propertyEntries = rawProperties.entrySet(); for (Map.Entry<Object, Object> property : propertyEntries) { String key = (String) property.getKey(); String value = (String) property.getValue(); value = substitutePropertyReferences(value); System.setProperty(key, value); } }
From source file:jsst.server.FrontController.java
private void initSystemProperties() throws ServletException { URL resource = FrontController.class.getClassLoader().getResource(ENVIRONMENT_PROPERTIES_FILE); if (resource != null) { Properties properties = new Properties(); try {/*from w w w . j a va2 s . c o m*/ InputStream inputStream = resource.openStream(); try { properties.load(inputStream); Set<Map.Entry<Object, Object>> entries = properties.entrySet(); for (Map.Entry<Object, Object> entry : entries) { System.setProperty((String) entry.getKey(), (String) entry.getValue()); } } finally { inputStream.close(); } } catch (IOException e) { throw new ServletException( "Unable to load system properties from " + ENVIRONMENT_PROPERTIES_FILE + " file", e); } } }
From source file:edu.mayo.cts2.framework.core.xml.DelegatingMarshaller.java
/** * Creates the map from properties.//from w w w .j ava 2 s. c o m * * @param resource the resource * @return the map */ private Map<String, String> createMapFromProperties(Properties props) { Map<String, String> returnMap = new HashMap<String, String>(); for (Entry<Object, Object> entry : props.entrySet()) { returnMap.put(StringUtils.trim((String) entry.getKey()), StringUtils.trim((String) entry.getValue())); } return returnMap; }
From source file:com.adaptris.interlok.types.DefaultSerializableMessage.java
/** * Convenience method to do the same as {@link #setMessageHeaders(Map)} converting any non-string * keys/values into Strings./*from w ww. j ava 2s.c o m*/ * * @param props the properties that should become message headers; null means to clear all * headers. * @return the current DefaultSerializableMessage object for method chaining * @see #setMessageHeaders(Map) */ public DefaultSerializableMessage withHeadersFromProperties(Properties props) { if (props == null) { setMessageHeaders(null); } else { Map<String, String> result = new HashMap<>(props.size()); for (Map.Entry e : props.entrySet()) { result.put(e.getKey().toString(), e.getValue().toString()); } setMessageHeaders(result); } return this; }
From source file:org.apache.hadoop.hbase.zookeeper.HQuorumPeer.java
static void writeMyID(Properties properties) throws IOException { long myId = -1; Configuration conf = HBaseConfiguration.create(); String myAddress = DNS.getDefaultHost(conf.get("hbase.zookeeper.dns.interface", "default"), conf.get("hbase.zookeeper.dns.nameserver", "default")); List<String> ips = new ArrayList<String>(); // Add what could be the best (configured) match ips.add(myAddress.contains(".") ? myAddress : StringUtils.simpleHostname(myAddress)); // For all nics get all hostnames and IPs Enumeration<?> nics = NetworkInterface.getNetworkInterfaces(); while (nics.hasMoreElements()) { Enumeration<?> rawAdrs = ((NetworkInterface) nics.nextElement()).getInetAddresses(); while (rawAdrs.hasMoreElements()) { InetAddress inet = (InetAddress) rawAdrs.nextElement(); ips.add(StringUtils.simpleHostname(inet.getHostName())); ips.add(inet.getHostAddress()); }// ww w . j ava2 s. c o m } for (Entry<Object, Object> entry : properties.entrySet()) { String key = entry.getKey().toString().trim(); String value = entry.getValue().toString().trim(); if (key.startsWith("server.")) { int dot = key.indexOf('.'); long id = Long.parseLong(key.substring(dot + 1)); String[] parts = value.split(":"); String address = parts[0]; if (addressIsLocalHost(address) || ips.contains(address)) { myId = id; break; } } } if (myId == -1) { throw new IOException( "Could not find my address: " + myAddress + " in list of ZooKeeper quorum servers"); } String dataDirStr = properties.get("dataDir").toString().trim(); File dataDir = new File(dataDirStr); if (!dataDir.isDirectory()) { if (!dataDir.mkdirs()) { throw new IOException("Unable to create data dir " + dataDir); } } File myIdFile = new File(dataDir, "myid"); PrintWriter w = new PrintWriter(myIdFile); w.println(myId); w.close(); }
From source file:org.apache.hadoop.mapred.ClusterMapReduceTestCase.java
/** * Starts the cluster within a testcase. * <p/>//from w ww. j a v a2s. co m * Note that the cluster is already started when the testcase method * is invoked. This method is useful if as part of the testcase the * cluster has to be shutdown and restarted again. * <p/> * If the cluster is already running this method does nothing. * * @param reformatDFS indicates if DFS has to be reformated * @param props configuration properties to inject to the mini cluster * @throws Exception if the cluster could not be started */ protected synchronized void startCluster(boolean reformatDFS, Properties props) throws Exception { if (dfsCluster == null) { JobConf conf = new JobConf(); if (props != null) { for (Map.Entry entry : props.entrySet()) { conf.set((String) entry.getKey(), (String) entry.getValue()); } } dfsCluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).format(reformatDFS).racks(null).build(); ConfigurableMiniMRCluster.setConfiguration(props); //noinspection deprecation mrCluster = new ConfigurableMiniMRCluster(2, getFileSystem().getUri().toString(), 1, conf, false); } }
From source file:com.baomidou.framework.spring.MutilPropertyPlaceholderConfigurer.java
/** * <p>// w w w. jav a2 s. com * ? prop * </p> * @param mergeProperties * spring Properties * @return */ protected Properties convertMergeProperties(Properties mergeProperties) { Properties prop = new Properties(); String runMode = "_" + getRunMode() + "_mode"; Set<Entry<Object, Object>> es = mergeProperties.entrySet(); for (Entry<Object, Object> entry : es) { String key = (String) entry.getKey(); String realKey = key; int idx = key.lastIndexOf("_mode"); if (idx > 0) { if (key.contains(runMode)) { realKey = key.substring(0, key.lastIndexOf(runMode)); } else { /** ?? */ realKey = null; } } /** * ??<br> * ?? */ if (realKey != null && !prop.containsKey(realKey)) { Object value = null; if (idx > 0) { value = mergeProperties.get(realKey + runMode); } else { value = mergeProperties.get(realKey); } if (value != null) { prop.put(realKey, value); } else { throw new SpringWindException("impossible empty property for " + realKey); } } } return prop; }
From source file:com.bellman.bible.service.readingplan.ReadingPlanDao.java
/** * get a list of all days readings in a plan *//*from w w w .j ava 2s. co m*/ public List<OneDaysReadingsDto> getReadingList(String planName) { ReadingPlanInfoDto planInfo = getReadingPlanInfoDto(planName); Properties properties = getPlanProperties(planName); List<OneDaysReadingsDto> list = new ArrayList<OneDaysReadingsDto>(); for (Entry<Object, Object> entry : properties.entrySet()) { String key = (String) entry.getKey(); String value = (String) entry.getValue(); if (StringUtils.isNumeric(key)) { int day = Integer.parseInt(key); OneDaysReadingsDto daysReading = new OneDaysReadingsDto(day, value, planInfo); list.add(daysReading); } } Collections.sort(list); return list; }
From source file:eu.openanalytics.rsb.message.MultiFilesJob.java
private void loadJobConfiguration(final InputStream is) throws IOException { final Properties jobConfiguration = new Properties(); jobConfiguration.load(is);/*from w w w .j a v a 2 s. c o m*/ final Map<String, Serializable> mergedMeta = new HashMap<String, Serializable>(); for (final Entry<?, ?> e : jobConfiguration.entrySet()) { mergedMeta.put(e.getKey().toString(), e.getValue().toString()); } // give priority to pre-existing metas by overriding the ones from the config // file mergedMeta.putAll(getMeta()); getMeta().clear(); getMeta().putAll(mergedMeta); }
From source file:ca.uhn.hunit.example.MllpHl7v2MessageSwapper.java
public MllpHl7v2MessageSwapper(boolean thePrintOutput, Properties theSubstitutions, int thePasses) { myPrintOutput = thePrintOutput;/*from w ww . ja v a 2 s . c o m*/ myIterations = thePasses; mySubstitutions = new HashMap<String, String>(); for (Map.Entry<Object, Object> next : theSubstitutions.entrySet()) { mySubstitutions.put(next.getKey().toString(), next.getValue().toString()); } }