List of usage examples for java.util Properties entrySet
@Override
public Set<Map.Entry<Object, Object>> entrySet()
From source file:org.apache.hadoop.hive.llap.cli.LlapServiceDriver.java
private static void populateConf(Configuration configured, Configuration target, Properties properties, String source) {/*from w ww .j a v a2 s . co m*/ for (Entry<Object, Object> entry : properties.entrySet()) { String key = (String) entry.getKey(); String val = configured.get(key); if (val != null) { target.set(key, val, source); } } }
From source file:org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil.java
/** * Assert that a set of properties files all contain the same data. * We cannot simply check the md5sums here, since Properties files * contain timestamps -- thus, two properties files from the same * saveNamespace operation may actually differ in md5sum. * @param propFiles the files to compare * @throws IOException if the files cannot be opened or read * @throws AssertionError if the files differ *//*from w ww.jav a 2s . co m*/ public static void assertPropertiesFilesSame(File[] propFiles) throws IOException { Set<Map.Entry<Object, Object>> prevProps = null; for (File f : propFiles) { Properties props; FileInputStream is = new FileInputStream(f); try { props = new Properties(); props.load(is); } finally { IOUtils.closeStream(is); } if (prevProps == null) { prevProps = props.entrySet(); } else { Set<Entry<Object, Object>> diff = Sets.symmetricDifference(prevProps, props.entrySet()); if (!diff.isEmpty()) { fail("Properties file " + f + " differs from " + propFiles[0]); } } } }
From source file:com.cloudera.flume.agent.FlumeNode.java
public static void logEnvironment(Logger log) { Properties props = System.getProperties(); for (Entry<Object, Object> p : props.entrySet()) { log.info("System property " + p.getKey() + "=" + p.getValue()); }// w w w . j a v a2 s. c o m }
From source file:edu.uci.ics.asterix.event.service.AsterixEventServiceUtil.java
private static void writeAsterixLogConfigurationFile(AsterixInstance asterixInstance, Properties logProperties) throws IOException, EventException { String asterixInstanceName = asterixInstance.getName(); Cluster cluster = asterixInstance.getCluster(); StringBuffer conf = new StringBuffer(); for (Map.Entry<Object, Object> p : logProperties.entrySet()) { conf.append(p.getKey() + "=" + p.getValue() + "\n"); }/*w ww.j av a 2 s .co m*/ for (Node node : cluster.getNode()) { String txnLogDir = node.getTxnLogDir() == null ? cluster.getTxnLogDir() : node.getTxnLogDir(); if (txnLogDir == null) { throw new EventException( "Transaction log directory (txn_log_dir) not configured for node: " + node.getId()); } conf.append(asterixInstanceName + "_" + node.getId() + "." + TXN_LOG_DIR_KEY_SUFFIX + "=" + txnLogDir + "\n"); } List<edu.uci.ics.asterix.common.configuration.Property> properties = asterixInstance .getAsterixConfiguration().getProperty(); for (edu.uci.ics.asterix.common.configuration.Property p : properties) { if (p.getName().trim().toLowerCase().contains("log")) { conf.append(p.getValue() + "=" + p.getValue()); } } dumpToFile(AsterixEventService.getAsterixDir() + File.separator + asterixInstanceName + File.separator + "log.properties", conf.toString()); }
From source file:br.msf.commons.util.CollectionUtils.java
public static Map<String, String> getSystemProps() { try {/*from w ww .j av a 2s. c o m*/ final Properties props = System.getProperties(); final Map<String, String> map = new LinkedHashMap<>(); for (Entry<Object, Object> entry : props.entrySet()) { map.put(entry.getKey().toString(), entry.getValue().toString()); } return map; } catch (SecurityException ex) { LOGGER.log(Level.WARNING, "Could not use System Properties.", ex); return Collections.EMPTY_MAP; } }
From source file:br.ojimarcius.commons.util.CollectionUtils.java
public static Map<String, String> getSystemProps() { try {/* w w w . j a v a 2s . c om*/ final Properties props = System.getProperties(); final Map<String, String> map = new LinkedHashMap<String, String>(); for (Entry<Object, Object> entry : props.entrySet()) { map.put(entry.getKey().toString(), entry.getValue().toString()); } return map; } catch (SecurityException ex) { LOGGER.log(Level.WARNING, "Could not use System Properties.", ex); return Collections.EMPTY_MAP; } }
From source file:com.halseyburgund.roundware.server.RWHttpManager.java
public static String uploadFile(String page, Properties properties, String fileParam, String file) throws Exception { if (D) {/*from ww w . j a va 2 s . co m*/ RWHtmlLog.i(TAG, "Starting upload of file: " + file, null); } HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIMEOUT_MSEC); HttpConnectionParams.setSoTimeout(httpParams, CONNECTION_TIMEOUT_MSEC); HttpClient httpClient = new DefaultHttpClient(httpParams); HttpPost request = new HttpPost(page); MultipartEntity entity = new MultipartEntity(); Iterator<Map.Entry<Object, Object>> i = properties.entrySet().iterator(); while (i.hasNext()) { Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) i.next(); String key = (String) entry.getKey(); String val = (String) entry.getValue(); entity.addPart(key, new StringBody(val)); if (D) { RWHtmlLog.i(TAG, "Added StringBody multipart for: '" + key + "' = '" + val + "'", null); } } File upload = new File(file); entity.addPart(fileParam, new FileBody(upload)); if (D) { String msg = "Added FileBody multipart for: '" + fileParam + "' = <'" + upload.getAbsolutePath() + ", size: " + upload.length() + " bytes >'"; RWHtmlLog.i(TAG, msg, null); } request.setEntity(entity); if (D) { RWHtmlLog.i(TAG, "Sending HTTP request...", null); } HttpResponse response = httpClient.execute(request); int st = response.getStatusLine().getStatusCode(); if (st == HttpStatus.SC_OK) { StringBuffer sbResponse = new StringBuffer(); InputStream content = response.getEntity().getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { sbResponse.append(line); } content.close(); // this will also close the connection if (D) { RWHtmlLog.i(TAG, "Upload successful (HTTP code: " + st + ")", null); RWHtmlLog.i(TAG, "Server response: " + sbResponse.toString(), null); } return sbResponse.toString(); } else { ByteArrayOutputStream ostream = new ByteArrayOutputStream(); entity.writeTo(ostream); RWHtmlLog.e(TAG, "Upload failed (http code: " + st + ")", null); RWHtmlLog.e(TAG, "Server response: " + ostream.toString(), null); throw new Exception(HTTP_POST_FAILED + st); } }
From source file:org.apache.axiom.om.util.StAXUtils.java
/** * Load factory properties from a resource. The context class loader is used to locate * the resource. The method converts boolean and integer values to the right Java types. * All other values are returned as strings. * /*from www .jav a2 s.c o m*/ * @param name * @return */ // This has package access since it is used from within anonymous inner classes static Map loadFactoryProperties(String name) { ClassLoader cl = getContextClassLoader(); InputStream in = cl.getResourceAsStream(name); if (in == null) { return null; } else { try { Properties rawProps = new Properties(); Map props = new HashMap(); rawProps.load(in); for (Iterator it = rawProps.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); String strValue = (String) entry.getValue(); Object value; if (strValue.equals("true")) { value = Boolean.TRUE; } else if (strValue.equals("false")) { value = Boolean.FALSE; } else { try { value = Integer.valueOf(strValue); } catch (NumberFormatException ex) { value = strValue; } } props.put(entry.getKey(), value); } if (log.isDebugEnabled()) { log.debug("Loaded factory properties from " + name + ": " + props); } return props; } catch (IOException ex) { log.error("Failed to read " + name, ex); return null; } finally { try { in.close(); } catch (IOException ex) { // Ignore } } } }
From source file:jetbrains.exodus.env.EnvironmentImpl.java
private static void applyEnvironmentSettings(@NotNull final String location, @NotNull final EnvironmentConfig ec) { final File propsFile = new File(location, ENVIRONMENT_PROPERTIES_FILE); if (propsFile.exists() && propsFile.isFile()) { try {//from w w w.j av a 2 s. c o m try (InputStream propsStream = new FileInputStream(propsFile)) { final Properties envProps = new Properties(); envProps.load(propsStream); for (final Map.Entry<Object, Object> entry : envProps.entrySet()) { ec.setSetting(entry.getKey().toString(), entry.getValue()); } } } catch (IOException e) { throw ExodusException.toExodusException(e); } } }
From source file:com.jkoolcloud.tnt4j.streams.configure.zookeeper.ZKConfigInit.java
/** * Loads uploader configuration and runs uploading process. * // ww w. j av a 2 s .c om * @param cfgFileName * uploader configuration file path */ private static void loadConfigAndRun(String cfgFileName) { if (StringUtils.isEmpty(cfgFileName)) { LOGGER.log(OpLevel.ERROR, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "ZKConfigInit.upload.cfg.not.defined")); return; } Properties zkup = ZKConfigManager.readStreamsZKConfig(cfgFileName); if (MapUtils.isNotEmpty(zkup)) { try { ZKConfigManager.openConnection(zkup); String streamsPath = zkup.getProperty(ZKConfigManager.PROP_ZK_STREAMS_PATH); Stat nodeStat = ZKConfigManager.zk().exists(streamsPath, false); if (clean && nodeStat != null) { LOGGER.log(OpLevel.INFO, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "ZKConfigInit.clearing.zk"), streamsPath); ZKUtil.deleteRecursive(ZKConfigManager.zk(), streamsPath); } byte[] cfgData; String cfgPath; for (Map.Entry<?, ?> pe : zkup.entrySet()) { String pk = (String) pe.getKey(); String pv = (String) pe.getValue(); if (!pk.startsWith("zk.")) { // NON-NLS cfgData = loadDataFromFile(pv); cfgPath = streamsPath + ZKConfigManager.PATH_DELIM + pk.replaceAll("\\.", ZKConfigManager.PATH_DELIM); // NON-NLS ZKConfigManager.setNodeData(ZKConfigManager.zk(), cfgPath, cfgData); } } } catch (Exception exc) { LOGGER.log(OpLevel.ERROR, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "ZKConfigInit.upload.error"), exc.getLocalizedMessage(), exc); } finally { ZKConfigManager.close(); } } }