List of usage examples for java.util Properties stringPropertyNames
public Set<String> stringPropertyNames()
From source file:org.pentaho.di.core.ConcurrentMapProperties.java
/** * Converts a Properties object to a ConcurrentMapProperties object * * @param props// w ww .java 2s .c om * @return A new ConcurrentMapProperties with all properties enumerated (including defaults) */ public static ConcurrentMapProperties convertProperties(Properties props) { if (props != null) { if (!(props instanceof ConcurrentMapProperties)) { ConcurrentMapProperties result = new ConcurrentMapProperties(null); synchronized (props) { for (String prop : props.stringPropertyNames()) { result.put(prop, props.getProperty(prop)); } } return result; } else { //Already a ConcurrentMapProperties return (ConcurrentMapProperties) props; } } return null; }
From source file:org.apache.hadoop.mapred.QueueConfigurationParser.java
/** * Construct an {@link Element} for a single queue, constructing the inner * queue <name/>, <properties/>, <state/> and the inner * <queue> elements recursively. * /* w ww . j a v a 2 s.co m*/ * @param document * @param jqi * @return */ static Element getQueueElement(Document document, JobQueueInfo jqi) { // Queue Element q = document.createElement(QUEUE_TAG); // Queue-name Element qName = document.createElement(QUEUE_NAME_TAG); qName.setTextContent(getSimpleQueueName(jqi.getQueueName())); q.appendChild(qName); // Queue-properties Properties props = jqi.getProperties(); Element propsElement = document.createElement(PROPERTIES_TAG); if (props != null) { Set<String> propList = props.stringPropertyNames(); for (String prop : propList) { Element propertyElement = document.createElement(PROPERTY_TAG); propertyElement.setAttribute(KEY_TAG, prop); propertyElement.setAttribute(VALUE_TAG, (String) props.get(prop)); propsElement.appendChild(propertyElement); } } q.appendChild(propsElement); // Queue-state String queueState = jqi.getState().getStateName(); if (queueState != null && !queueState.equals(QueueState.UNDEFINED.getStateName())) { Element qStateElement = document.createElement(STATE_TAG); qStateElement.setTextContent(queueState); q.appendChild(qStateElement); } // Queue-children List<JobQueueInfo> children = jqi.getChildren(); if (children != null) { for (JobQueueInfo child : children) { q.appendChild(getQueueElement(document, child)); } } return q; }
From source file:adalid.commons.properties.PropertiesHandler.java
private static void log(Properties properties, Level level) { String[] names = new String[properties.stringPropertyNames().size()]; properties.stringPropertyNames().toArray(names); Arrays.sort(names);/*from ww w. j av a2s . c o m*/ String value; for (String name : names) { value = properties.getProperty(name); logger.log(level, name + " = " + (StringUtils.containsIgnoreCase(name, "password") ? "***" : value)); } }
From source file:com.twitter.hraven.Cluster.java
static void loadHadoopClustersProps(String filename) { // read the property file // populate the map Properties prop = new Properties(); if (StringUtils.isBlank(filename)) { filename = Constants.HRAVEN_CLUSTER_PROPERTIES_FILENAME; }/*from w w w.j a v a 2 s . co m*/ try { //TODO : property file to be moved out from resources into config dir InputStream inp = Cluster.class.getResourceAsStream("/" + filename); if (inp == null) { LOG.error(filename + " for mapping clusters to cluster identifiers in hRaven does not exist"); return; } prop.load(inp); Set<String> hostnames = prop.stringPropertyNames(); for (String h : hostnames) { CLUSTERS_BY_HOST.put(h, prop.getProperty(h)); } } catch (IOException e) { // An ExceptionInInitializerError will be thrown to indicate that an // exception occurred during evaluation of a static initializer or the // initializer for a static variable. throw new ExceptionInInitializerError(" Could not load properties file " + filename + " for mapping clusters to cluster identifiers in hRaven"); } }
From source file:org.tinymediamanager.core.License.java
public static boolean encrypt(Properties props) { try {//from w w w.j av a2s . c om if (props == null || props.size() == 0) { return false; } String request = "https://script.google.com/macros/s/AKfycbz7gu6I046KesXCHJJe6OEPX2tx18RcfiMS5Id-7NXsNYYMnLvK/exec"; String urlParameters = "mac=" + getMac(); for (String key : props.stringPropertyNames()) { String value = props.getProperty(key); urlParameters += "&" + key + "=" + URLEncoder.encode(value, "UTF-8"); } HttpURLConnection connection = new OkUrlFactory(TmmHttpClient.getHttpClient()).open(new URL(request)); connection.setDoOutput(true); connection.setDoInput(true); connection.setInstanceFollowRedirects(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("charset", "utf-8"); connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length)); connection.setUseCaches(false); OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); writer.write(urlParameters); writer.flush(); String response = IOUtils.toString(new InputStreamReader(connection.getInputStream(), "UTF-8")); writer.close(); if (response != null && response.isEmpty()) { LOGGER.warn("empty response at license generation; code " + connection.getResponseCode()); return false; } // GET method // StringWriter writer = new StringWriter(); // IOUtils.copy(url.getInputStream(), writer, "UTF-8"); // String response = writer.toString(); File f = new File(LICENSE_FILE); if (Globals.isRunningJavaWebStart()) { // when in webstart, put it in user home f = new File(System.getProperty("user.home") + File.separator + ".tmm", LICENSE_FILE); if (!f.getParentFile().exists()) { f.getParentFile().mkdir(); } } FileUtils.writeStringToFile(f, response); return true; } catch (Exception e) { LOGGER.error("Error generating license", e); return false; } }
From source file:org.wso2.carbon.apimgt.hybrid.gateway.configurator.Configurator.java
/** * Retrieves all the properties from property file * * @param gatewayProperties//from w ww.j a va2 s. co m * @param propertyKeyPrefix * @return all property keys and values in a map */ private static Map<String, String> getAllPropertiesForPrefix(Properties gatewayProperties, String propertyKeyPrefix) { Map<String, String> allPropertyKeyValueMap = new HashMap<>(); for (String key : gatewayProperties.stringPropertyNames()) { if (key.startsWith(propertyKeyPrefix)) { allPropertyKeyValueMap.put(key, gatewayProperties.getProperty(key)); } } if (log.isDebugEnabled()) { log.debug("Retrieving all the properties for the prefix: " + propertyKeyPrefix + ". Found key," + "value map: " + allPropertyKeyValueMap); } return allPropertyKeyValueMap; }
From source file:org.commonjava.maven.ext.core.util.PropertiesUtils.java
/** * Filter Properties by accepting only properties with names that start with prefix. Trims the prefix * from the property names when inserting them into the returned Map. * @param properties the properties to filter. * @param prefix The String that must be at the start of the property names * @return map of properties with matching prepend and their values *//* ww w . j av a 2 s. com*/ public static Map<String, String> getPropertiesByPrefix(final Properties properties, final String prefix) { final Map<String, String> matchedProperties = new HashMap<>(); final int prefixLength = prefix.length(); for (final String propertyName : properties.stringPropertyNames()) { if (propertyName.startsWith(prefix)) { final String trimmedPropertyName = propertyName.substring(prefixLength); String value = properties.getProperty(propertyName); if (value != null && value.equals("true")) { logger.warn("Work around Brew/Maven bug - removing erroneous 'true' value for {}.", trimmedPropertyName); value = ""; } matchedProperties.put(trimmedPropertyName, value); } } return matchedProperties; }
From source file:org.commonjava.indy.koji.content.testutil.KojiMockHandlers.java
public static void configureKojiServer(ExpectationServer server, String urlBase, AtomicInteger exchangeCounter, String resourceBase, boolean verifyArtifacts, String verifyBasepath) { try (InputStream scriptIn = Thread.currentThread().getContextClassLoader() .getResourceAsStream(Paths.get(resourceBase, MOCK_SCRIPT_JSON).toString())) { if (scriptIn == null) { fail("Cannot find script description file: " + MOCK_SCRIPT_JSON + " in: " + resourceBase); }/*from w w w . j a v a 2 s. co m*/ if (verifyArtifacts) { Properties checksums = new Properties(); String checksumsProperties = resourceBase + "/checksums.properties"; try (InputStream in = Thread.currentThread().getContextClassLoader() .getResourceAsStream(checksumsProperties)) { if (in == null) { fail("Cannot find checksums resource in classpath: '" + checksumsProperties + "'"); } checksums.load(in); } for (String path : checksums.stringPropertyNames()) { server.expect("GET", server.formatUrl(verifyBasepath, path), 200, checksums.getProperty(path)); } } ObjectMapper mapper = new ObjectMapper(); MockScript mockScript = mapper.readValue(scriptIn, MockScript.class); mockScript.setCounter(exchangeCounter); server.expect("POST", server.formatUrl(urlBase), kojiMessageHandler(mockScript, resourceBase)); server.expect("POST", server.formatUrl(urlBase, "ssllogin"), kojiMessageHandler(mockScript, resourceBase)); } catch (Exception e) { e.printStackTrace(); fail("Failed to serve xml-rpc request. " + e.getMessage()); } }
From source file:org.dcm4che3.tool.dcmqrscp.DcmQRSCP.java
private static void addTransferCapabilities(ApplicationEntity ae, Properties p, TransferCapability.Role role, EnumSet<QueryOption> queryOptions) { for (String cuid : p.stringPropertyNames()) { String ts = p.getProperty(cuid); TransferCapability tc = new TransferCapability(null, CLIUtils.toUID(cuid), role, CLIUtils.toUIDs(ts)); tc.setQueryOptions(queryOptions); ae.addTransferCapability(tc);// w w w . ja v a 2s . co m } }
From source file:pcgen.system.Main.java
private static void logSystemProps() { Properties props = System.getProperties(); StringWriter writer = new StringWriter(); PrintWriter pwriter = new PrintWriter(writer); pwriter.println();//from w w w.j av a 2 s. co m pwriter.println("-- listing properties --"); //$NON-NLS-1$ // Manually output the property values to avoid them being cut off at 40 characters Set<String> keys = props.stringPropertyNames(); //$NON-NLS-1$ keys.forEach(key -> { pwriter.println(key + '=' + props.getProperty(key)); }); Logging.log(Level.CONFIG, writer.toString()); }