Java Code Examples for java.util.Properties.entrySet()

The following are Jave code examples for showing how to use entrySet() of the java.util.Properties class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ProjectAres   File: LoggingConfig.java   Source Code and License Vote up 7 votes
public void load() {
    try {
        Logger.getLogger("").setLevel(Level.INFO);

        final Properties properties = new Properties();
        try { properties.load(new FileInputStream("logging.properties")); }
        catch(FileNotFoundException ignored) {}

        for(Map.Entry<Object, Object> entry : properties.entrySet()) {
            String[] parts = entry.getKey().toString().split("\\.");
            if(parts.length == 2 && "level".equals(parts[1])) {
                String loggerName = parts[0];
                String levelName = (String) entry.getValue();
                if("root".equals(loggerName)) {
                    loggerName = "";
                }
                Logging.setDefaultLevel(loggerName, Level.parse(levelName));
            }
        }

        Logging.updateFromLoggingProperties();
    } catch(IOException | NoSuchFieldException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        logger.log(Level.WARNING, "Error applying logging config", e);
    }
}
 
Example 2
Project: incubator-netbeans   File: RemotePlatformProbe.java   Source Code and License Vote up 6 votes
@NonNull
public static Pair<Map<String,String>,Map<String,String>> getSystemProperties(@NonNull final Properties p) {
    final Map<String,String> sysProps = new HashMap<>();
    final Map<String,String> properties = new HashMap<>();
    for (Map.Entry<Object,Object> e : p.entrySet()) {
        String key = (String) e.getKey();
        String value = (String) e.getValue();
        if (key.startsWith(NB_PROP_PREFIX)) {
            properties.put(
                String.format(
                    "%s%s", //NOI18N
                    PLATFROM_PROP_PREFIX,
                    key.substring(NB_PROP_PREFIX.length())),
                value);
        } else {
            sysProps.put(key, value);
        }
    }
    return Pair.<Map<String,String>,Map<String,String>>of(properties,sysProps);
}
 
Example 3
Project: dds-examples   File: ConfigurationFilterProvider.java   Source Code and License Vote up 6 votes
/**
 * Loads the configuration from the properties.
 *
 * @param properties the properties to load
 */
private void loadConfiguration(
    final Properties properties
) {
  for (Entry<Object, Object> entry : properties.entrySet()) {
    // run the matcher
    Matcher entryMatch = patternConfigurationItem.matcher(entry.getKey().toString());

    // result valid?
    if (!entryMatch.matches()) {
      continue;
    }

    // load property
    loadProperty(
        entryMatch.group(1),
        entryMatch.group(2),
        entry.getValue().toString()
    );
  }

  // log configuration
  logConfiguration();
}
 
Example 4
Project: ditb   File: ZKServerTool.java   Source Code and License Vote up 6 votes
public static ServerName[] readZKNodes(Configuration conf) {
  List<ServerName> hosts = new LinkedList<ServerName>();

  // Note that we do not simply grab the property
  // HConstants.ZOOKEEPER_QUORUM from the HBaseConfiguration because the
  // user may be using a zoo.cfg file.
  Properties zkProps = ZKConfig.makeZKProps(conf);
  for (Entry<Object, Object> entry : zkProps.entrySet()) {
    String key = entry.getKey().toString().trim();
    String value = entry.getValue().toString().trim();
    if (key.startsWith("server.")) {
      String[] parts = value.split(":");
      String host = parts[0];

      int port = HConstants.DEFAULT_ZOOKEPER_CLIENT_PORT;
      if (parts.length > 1) {
        port = Integer.parseInt(parts[1]);
      }
      hosts.add(ServerName.valueOf(host, port, -1));
    }
  }
  return hosts.toArray(new ServerName[hosts.size()]);
}
 
Example 5
Project: hadoop   File: LoggedJob.java   Source Code and License Vote up 6 votes
private void compareJobProperties(JobProperties jprop1, JobProperties jprop2,
                                  TreePath loc, String eltname) 
throws DeepInequalityException {
  if (jprop1 == null && jprop2 == null) {
    return;
  }

  if (jprop1 == null || jprop2 == null) {
    throw new DeepInequalityException(eltname + " miscompared", 
                                      new TreePath(loc, eltname));
  }

  Properties prop1 = jprop1.getValue();
  Properties prop2 = jprop2.getValue();
  
  if (prop1.size() != prop2.size()) {
    throw new DeepInequalityException(eltname + " miscompared [size]", 
                                      new TreePath(loc, eltname));
  }
  
  for (Map.Entry<Object, Object> entry : prop1.entrySet()) {
    String v1 = entry.getValue().toString();
    String v2 = prop2.get(entry.getKey()).toString();
    compare1(v1, v2, new TreePath(loc, eltname), "key:" + entry.getKey());
  }
}
 
Example 6
Project: lams   File: Configuration.java   Source Code and License Vote up 5 votes
/**
 * Adds the incoming properties to the internal properties structure, as long as the internal structure does not
 * already contain an entry for the given key.
 *
 * @param properties The properties to merge
 *
 * @return this for ethod chaining
 */
public Configuration mergeProperties(Properties properties) {
	for ( Map.Entry entry : properties.entrySet() ) {
		if ( this.properties.containsKey( entry.getKey() ) ) {
			continue;
		}
		this.properties.setProperty( (String) entry.getKey(), (String) entry.getValue() );
	}
	return this;
}
 
Example 7
Project: dooo   File: WxzConfPropertiesFactoryBean.java   Source Code and License Vote up 5 votes
@Override
protected Properties createProperties() throws IOException {
    ConfigCollectionFactory configCollectionFactory = RemoteConfigCollectionFactoryBuilder.getInstance();
    if (configApps == null || configApps.size() == 0) {
        return super.createProperties();
    }
    Map<ConfigApp, Map<String, String>> allDatas = WxzConfManager.getInstance().load(configApps);
    Properties properties = new Properties();
    for (Map.Entry<ConfigApp, Map<String, String>> entry0 : allDatas.entrySet()) {
        for (Map.Entry<String, String> entry : entry0.getValue().entrySet()) {
            //处理properties文件
            if (PropertiesUtils.SUFFIX.equalsIgnoreCase(FilenameUtils.getExtension(entry.getKey()))) {
                try {
                    Properties p = PropertiesUtils.readFromText(entry.getValue());
                    p.load(new StringReader(entry.getValue()));
                    for (Map.Entry<Object, Object> objectEntry : p.entrySet()) {
                        //将配置重复的项打印出来
                        if (properties.containsKey(objectEntry.getKey())) {
                            LOGGER.warn("key {} will be overrided,original value {},new value {}", objectEntry.getKey(), properties.get(objectEntry.getKey()), objectEntry.getValue());
                        }
                        properties.put(objectEntry.getKey(), objectEntry.getValue());
                    }
                } catch (IOException e) {
                    LOGGER.error(entry.toString(), e);
                }
            }
        }
    }

    return properties;
}
 
Example 8
Project: lams   File: ContentNegotiationManagerFactoryBean.java   Source Code and License Vote up 5 votes
/**
 * Add mappings from file extensions to media types represented as strings.
 * <p>When this mapping is not set or when an extension is not found, the Java
 * Action Framework, if available, may be used if enabled via
 * {@link #setFavorPathExtension(boolean)}.
 * @see #addMediaType(String, MediaType)
 * @see #addMediaTypes(Map)
 */
public void setMediaTypes(Properties mediaTypes) {
	if (!CollectionUtils.isEmpty(mediaTypes)) {
		for (Entry<Object, Object> entry : mediaTypes.entrySet()) {
			String extension = ((String)entry.getKey()).toLowerCase(Locale.ENGLISH);
			this.mediaTypes.put(extension, MediaType.valueOf((String) entry.getValue()));
		}
	}
}
 
Example 9
Project: openjdk-jdk10   File: ReflectionOptionDescriptors.java   Source Code and License Vote up 5 votes
/**
 * Extracts name/value entries from a set of properties based on a given name prefix.
 *
 * @param properties the properties set to extract from
 * @param prefix entries whose names start with this prefix are extracted
 * @param stripPrefix specifies whether to remove the prefix from the names in the returned map
 */
public static EconomicMap<String, String> extractEntries(Properties properties, String prefix, boolean stripPrefix) {
    EconomicMap<String, String> matches = EconomicMap.create();
    for (Map.Entry<Object, Object> e : properties.entrySet()) {
        String name = (String) e.getKey();
        if (name.startsWith(prefix)) {
            String value = (String) e.getValue();
            if (stripPrefix) {
                name = name.substring(prefix.length());
            }
            matches.put(name, value);
        }
    }
    return matches;
}
 
Example 10
Project: incubator-netbeans   File: ActionProviderSupport.java   Source Code and License Vote up 5 votes
/**
 * Loads targets for specific commands from shared config property file.
 * @returns map; key=command name; value=array of targets for given command
 */
@NonNull
static Map<String,String[]> loadTargetsFromConfig(
        @NonNull final Project project,
        @NonNull final PropertyEvaluator evaluator) {
    final Map<String,String[]> targets = new HashMap<>(6);
    final String config = evaluator.getProperty(ProjectProperties.PROP_PROJECT_CONFIGURATION_CONFIG);
    // load targets from shared config
    FileObject propFO = project.getProjectDirectory().getFileObject("nbproject/configs/" + config + ".properties");
    if (propFO == null) {
        return targets;
    }
    final Properties props = new Properties();
    try (InputStream is = propFO.getInputStream()) {
            props.load(is);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
        return targets;
    }
    for (Map.Entry<Object,Object> e : props.entrySet()) {
        final String propName = (String) e.getKey();
        if (propName.startsWith("$target.")) {
            final String tNameVal = (String) e.getValue();
            if (tNameVal != null && !tNameVal.isEmpty()) {
                final String cmdNameKey = propName.substring("$target.".length());
                final StringTokenizer stok = new StringTokenizer(tNameVal.trim(), " ");
                List<String> targetNames = new ArrayList<>(3);
                while (stok.hasMoreTokens()) {
                    targetNames.add(stok.nextToken());
                }
                targets.put(cmdNameKey, targetNames.toArray(new String[targetNames.size()]));
            }
        }
    }
    return targets;
}
 
Example 11
Project: incubator-netbeans   File: PropertiesProvider.java   Source Code and License Vote up 5 votes
@Override
public Map<String, ?> attributesFor(DataObject template, DataFolder target, String name) {
    FileObject dir = FileUtil.getConfigFile("Templates/Properties");
    if (dir == null) {
        return Collections.emptyMap();
    }
    Charset set;
    InputStream is;
    
    Map<String, Object> ret = new HashMap<>();
    for (Enumeration<? extends FileObject> en = dir.getChildren(true); en.hasMoreElements(); ) {
        try {
            FileObject fo = en.nextElement();
            Properties p = new Properties();
            is = fo.getInputStream();
            p.load(is);
            is.close();
            for (Map.Entry<Object, Object> entry : p.entrySet()) {
                if (entry.getKey() instanceof String) {
                    String key = (String) entry.getKey();
                    if (!ret.containsKey(key)) {
                        ret.put(key, entry.getValue());
                    }
                }
            }
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    return ret;
}
 
Example 12
Project: launcher-backend   File: VersionHelper.java   Source Code and License Vote up 5 votes
protected static Map<String, String> getGroupArtifactVersionMap() {
    if(groupArtifactVersionMap == null) {
        groupArtifactVersionMap = new HashMap<>();
        InputStream in = VersionHelper.class.getResourceAsStream("versions.properties");
        if(in == null) {
            LOG.warn("Could not find versions.properties on the classpath!");
        } else {
            Properties properties = new Properties();

            try {
                properties.load(in);
            } catch (IOException var7) {
                throw new RuntimeException("Failed to load versions.properties: " + var7, var7);
            }

            Set entries = properties.entrySet();

            for (Object entry1 : entries) {
                Map.Entry entry = (Map.Entry) entry1;
                Object key = entry.getKey();
                Object value = entry.getValue();
                if (key != null && value != null) {
                    groupArtifactVersionMap.put(key.toString(), value.toString());
                }
            }
        }
    }

    return groupArtifactVersionMap;
}
 
Example 13
Project: marathonv5   File: PropertyHelper.java   Source Code and License Vote up 5 votes
public static String toCSS(Properties properties) {
    Entry<Object, Object> typeProperty = null;
    Entry<Object, Object> indexProperty = null;
    Entry<Object, Object> tagNameProperty = null;

    StringBuilder sb = new StringBuilder();
    Set<Entry<Object, Object>> entries = properties.entrySet();
    for (Entry<Object, Object> entry : entries) {
        if (entry.getKey().equals("type")) {
            typeProperty = entry;
        } else if (entry.getKey().equals("indexOfType")) {
            indexProperty = entry;
        } else if (entry.getKey().equals("tagName")) {
            tagNameProperty = entry;
        } else {
            String value = entry.getValue().toString();
            value = value.replaceAll("\\\\", "\\\\\\\\").replaceAll("'", "\\\\'");
            sb.append("[").append(entry.getKey().toString()).append("=").append("'").append(value).append("']");
        }
    }
    String r = sb.toString();
    if (tagNameProperty != null) {
        r = tagNameProperty.getValue().toString();
    }
    if (typeProperty != null) {
        r = "[" + typeProperty.getKey().toString() + "=" + "'" + typeProperty.getValue().toString() + "']" + sb.toString();
    }
    if (indexProperty != null) {
        int index = Integer.parseInt(indexProperty.getValue().toString());
        r = r + ":nth(" + (index + 1) + ")";
    }
    return r;
}
 
Example 14
Project: jwala   File: PropertyFilesConfigurationImpl.java   Source Code and License Vote up 5 votes
public void load(Properties fmProperties) {         
    for(JwalaPath path : JwalaPath.values()) {
        paths.put(path, path.getDefaultPath());
    }

    for(Map.Entry<Object, Object> e : fmProperties.entrySet()) {
        if(e.getKey().toString().startsWith("paths.")) {
            for(Map.Entry<JwalaPath, Path> entry : paths.entrySet()) {
                if(entry.getKey().getProperty().equalsIgnoreCase(e.getKey().toString())) {
                    entry.setValue(defaultFs.getPath(e.getValue().toString()));
                }
            }
        }
    }
}
 
Example 15
Project: boohee_v5.6   File: RxJavaPlugins.java   Source Code and License Vote up 5 votes
static Object getPluginImplementationViaProperty(Class<?> pluginClass, Properties props) {
    String classSimpleName = pluginClass.getSimpleName();
    String pluginPrefix = "rxjava.plugin.";
    String implementingClass = props.getProperty("rxjava.plugin." + classSimpleName + ".implementation");
    if (implementingClass == null) {
        String classSuffix = ".class";
        String implSuffix = ".impl";
        for (Entry<Object, Object> e : props.entrySet()) {
            String key = e.getKey().toString();
            if (key.startsWith("rxjava.plugin.") && key.endsWith(".class") && classSimpleName.equals(e.getValue().toString())) {
                String implKey = "rxjava.plugin." + key.substring(0, key.length() - ".class".length()).substring("rxjava.plugin.".length()) + ".impl";
                implementingClass = props.getProperty(implKey);
                if (implementingClass == null) {
                    throw new RuntimeException("Implementing class declaration for " + classSimpleName + " missing: " + implKey);
                }
            }
        }
    }
    if (implementingClass == null) {
        return null;
    }
    try {
        return Class.forName(implementingClass).asSubclass(pluginClass).newInstance();
    } catch (ClassCastException e2) {
        throw new RuntimeException(classSimpleName + " implementation is not an instance of " + classSimpleName + ": " + implementingClass);
    } catch (ClassNotFoundException e3) {
        throw new RuntimeException(classSimpleName + " implementation class not found: " + implementingClass, e3);
    } catch (InstantiationException e4) {
        throw new RuntimeException(classSimpleName + " implementation not able to be instantiated: " + implementingClass, e4);
    } catch (IllegalAccessException e5) {
        throw new RuntimeException(classSimpleName + " implementation not able to be accessed: " + implementingClass, e5);
    }
}
 
Example 16
Project: properlty   File: SystemPropertiesReader.java   Source Code and License Vote up 5 votes
@Override
public Map<String, PropertyValue> read() {
	final Map<String, PropertyValue> properties = new HashMap<>();
	final Properties systemProperties = System.getProperties();
	for(final Entry<Object, Object> x : systemProperties.entrySet()) {
	    properties.put((String)x.getKey(), PropertyValue.of((String)x.getValue()));
	}
	return properties;
}
 
Example 17
Project: gitplex-mit   File: ServerProperties.java   Source Code and License Vote up 4 votes
public ServerProperties(Properties properties) {
	for (Map.Entry<Object, Object> entry: properties.entrySet()) {
		put(entry.getKey(), entry.getValue());
	}
}
 
Example 18
Project: https-github.com-apache-zookeeper   File: QuorumPeerConfig.java   Source Code and License Vote up 4 votes
/**
 * Edit static config file.
 * If there are quorum information in static file, e.g. "server.X", "group",
 * it will remove them.
 * If it needs to erase client port information left by the old config,
 * "eraseClientPortAddress" should be set true.
 * It should also updates dynamic file pointer on reconfig.
 */
public static void editStaticConfig(final String configFileStr,
                                    final String dynamicFileStr,
                                    final boolean eraseClientPortAddress)
        throws IOException {
    // Some tests may not have a static config file.
    if (configFileStr == null)
        return;

    File configFile = (new VerifyingFileFactory.Builder(LOG)
            .warnForRelativePath()
            .failForNonExistingPath()
            .build()).create(configFileStr);

    final File dynamicFile = (new VerifyingFileFactory.Builder(LOG)
            .warnForRelativePath()
            .failForNonExistingPath()
            .build()).create(dynamicFileStr);
    
    final Properties cfg = new Properties();
    FileInputStream in = new FileInputStream(configFile);
    try {
        cfg.load(in);
    } finally {
        in.close();
    }

    new AtomicFileWritingIdiom(new File(configFileStr), new WriterStatement() {
        @Override
        public void write(Writer out) throws IOException {
            for (Entry<Object, Object> entry : cfg.entrySet()) {
                String key = entry.getKey().toString().trim();

                if (key.startsWith("server.")
                    || key.startsWith("group")
                    || key.startsWith("weight")
                    || key.startsWith("dynamicConfigFile")
                    || key.startsWith("peerType")
                    || (eraseClientPortAddress
                        && (key.startsWith("clientPort")
                            || key.startsWith("clientPortAddress")))) {
                    // not writing them back to static file
                    continue;
                }

                String value = entry.getValue().toString().trim();
                out.write(key.concat("=").concat(value).concat("\n"));
            }

            // updates the dynamic file pointer
            String dynamicConfigFilePath = PathUtils.normalizeFileSystemPath(dynamicFile.getCanonicalPath());
            out.write("dynamicConfigFile="
                     .concat(dynamicConfigFilePath)
                     .concat("\n"));
        }
    });
}
 
Example 19
Project: hadoop-oss   File: Configuration.java   Source Code and License Vote up 4 votes
private void overlay(Properties to, Properties from) {
  for (Entry<Object, Object> entry: from.entrySet()) {
    to.put(entry.getKey(), entry.getValue());
  }
}
 
Example 20
Project: otter-G   File: OtterManagerLauncher.java   Source Code and License Vote up 4 votes
private static void mergeProps(Properties props) {
    for (Entry<Object, Object> entry : props.entrySet()) {
        System.setProperty((String) entry.getKey(), (String) entry.getValue());
    }
}