Java Code Examples for java.util.Properties#keySet()

The following examples show how to use java.util.Properties#keySet() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: DDMQ   File: GetBrokerConfigCommand.java    License: Apache License 2.0 6 votes vote down vote up
protected void getAndPrint(final MQAdminExt defaultMQAdminExt, final String printPrefix, final String addr)
    throws InterruptedException, RemotingConnectException,
    UnsupportedEncodingException, RemotingTimeoutException,
    MQBrokerException, RemotingSendRequestException {

    System.out.print(printPrefix);

    Properties properties = defaultMQAdminExt.getBrokerConfig(addr);
    if (properties == null) {
        System.out.printf("Broker[%s] has no config property!\n", addr);
        return;
    }

    for (Object key : properties.keySet()) {
        System.out.printf("%-50s=  %s\n", key, properties.get(key));
    }

    System.out.printf("%n");
}
 
Example 2
private String formatSystemProperties(Properties properties) {
    StringBuffer text = new StringBuffer(200);
    List keys = new ArrayList(properties.keySet());
    Iterator keyIt;

    Collections.sort(keys);
    keyIt = keys.iterator();
    while (keyIt.hasNext()) {
        String key = (String) keyIt.next();
        String val = properties.getProperty(key);

        text.append("<b>"); // NOI18N

        text.append(key);
        text.append("</b>=");   // NOI18N

        text.append(val);
        text.append("<br>");    // NOI18N

    }
    return text.toString();
}
 
Example 3
Source Project: bazel   File: Bazel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Builds the standard build info map from the loaded properties. The returned value is the list
 * of "build.*" properties from the build-data.properties file. The final key is the original one
 * striped, dot replaced with a space and with first letter capitalized. If the file fails to
 * load the returned map is empty.
 */
private static ImmutableMap<String, String> tryGetBuildInfo() {
  try (InputStream in = Bazel.class.getResourceAsStream(BUILD_DATA_PROPERTIES)) {
    if (in == null) {
      return ImmutableMap.of();
    }
    Properties props = new Properties();
    props.load(in);
    ImmutableMap.Builder<String, String> buildData = ImmutableMap.builder();
    for (Object key : props.keySet()) {
      String stringKey = key.toString();
      if (stringKey.startsWith("build.")) {
        // build.label -> Build label, build.timestamp.as.int -> Build timestamp as int
        String buildDataKey = "B" + stringKey.substring(1).replace('.', ' ');
        buildData.put(buildDataKey, props.getProperty(stringKey, ""));
      }
    }
    return buildData.build();
  } catch (IOException ignored) {
    return ImmutableMap.of();
  }
}
 
Example 4
@Override
public void init(Properties properties) {

    super.init(properties);
    for (Object o : properties.keySet()) {
        if (o != null) {
            String name = (String) o;
            String value = (String) properties.get(name);
            addConfigProperty(name, value);
        }
    }
    log.debug("EI lightweight registry is initialized.");

}
 
Example 5
private static void contributeDefaults(Map<String, Object> defaults, Resource resource) {
	if (resource.exists()) {
		YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
		yamlPropertiesFactoryBean.setResources(resource);
		yamlPropertiesFactoryBean.afterPropertiesSet();
		Properties p = yamlPropertiesFactoryBean.getObject();
		for (Object k : p.keySet()) {
			String key = k.toString();
			defaults.put(key, p.get(key));
		}
	}
}
 
Example 6
public void setOrganizationSettings(String orgId,
        Properties organizationProperties) throws ObjectNotFoundException {
    

    Organization organization = getOrganization(orgId);
    // first remove all existing settings
    Query query = ds
            .createNamedQuery("OrganizationSetting.removeAllForOrganization");
    query.setParameter("organization", organization);
    query.executeUpdate();

    if (organizationProperties != null) {
        List<OrganizationSetting> settings = new ArrayList<OrganizationSetting>();
        for (Object e : organizationProperties.keySet()) {
            String key = (String) e;
            if (!SettingType.contains(key)) {
                logger.logWarn(
                        Log4jLogger.SYSTEM_LOG,
                        LogMessageIdentifier.WARN_IGNORE_ILLEGAL_ORGANIZATION_SETTING,
                        key);
            } else {
                OrganizationSetting setting = createOrganizationSetting(
                        organization, key,
                        organizationProperties.getProperty(key));
                settings.add(setting);
            }
        }
        // now assign the settings to the organization
        // (may be empty if no properties provided)
        organization.setOrganizationSettings(settings);
    }
    
}
 
Example 7
Source Project: common-project   File: PlatformUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static void loadPropertiesFromFile(final File file) {
    Properties p = new Properties();
    try {
        InputStream in = new FileInputStream(file);
        p.load(in);
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (javafxPlatform == null) {
        javafxPlatform = p.getProperty("javafx.platform");
    }
    String prefix = javafxPlatform + ".";
    int prefixLength = prefix.length();
    boolean foundPlatform = false;
    for (Object o : p.keySet()) {
        String key = (String)o;
        if (key.startsWith(prefix)) {
            foundPlatform = true;
            String systemKey = key.substring(prefixLength);
            if (System.getProperty(systemKey) == null) {
                String value = p.getProperty(key);
                System.setProperty(systemKey, value);
            }
        }
    }
    if (!foundPlatform) {
        System.err.println("Warning: No settings found for javafx.platform='" + javafxPlatform + "'");
    }
}
 
Example 8
Source Project: datafu   File: ReduceEstimator.java    License: Apache License 2.0 5 votes vote down vote up
public ReduceEstimator(FileSystem fs, Properties props)
{
  this.fs = fs;
  
  if (props != null)
  {
    for (Object o : props.keySet())
    {
      String key = (String)o;
      if (key.startsWith("num.reducers."))
      {
        if (key.equals("num.reducers.bytes.per.reducer"))
        {
          tagToBytesPerReducer.put(DEFAULT, Long.parseLong(props.getProperty(key)));
        }
        else
        {
          Pattern p = Pattern.compile("num\\.reducers\\.([a-z]+)\\.bytes\\.per\\.reducer");
          Matcher m = p.matcher(key);
          if (m.matches())
          {
            String tag = m.group(1);
            tagToBytesPerReducer.put(tag, Long.parseLong(props.getProperty(key)));
          }
          else
          {
            throw new RuntimeException("Property not recognized: " + key);
          }
        }
      }
    }
  }
  
  if (!tagToBytesPerReducer.containsKey(DEFAULT))
  {
    long defaultValue = DEFAULT_BYTES_PER_REDUCER;
    _log.info(String.format("No default bytes per reducer set, using %.2f MB",toMB(defaultValue)));
    tagToBytesPerReducer.put(DEFAULT, defaultValue);
  }
}
 
Example 9
private void merge(Properties from, Properties to) {
    for (Object key : from.keySet()) {
        Object fromObj = from.get(key), toObj = to.get(key);
        if (toObj != null && !toObj.equals(fromObj)) {
            log.info("Replace, key: {}, value: {} -> {}", key, toObj, fromObj);
        }
        to.put(key, fromObj);
    }
}
 
Example 10
private void appendConnectionAttributes(NativePacketPayload buf, String attributes, String enc) {

        NativePacketPayload lb = new NativePacketPayload(100);
        Properties props = getConnectionAttributesAsProperties(attributes);

        for (Object key : props.keySet()) {
            lb.writeBytes(StringSelfDataType.STRING_LENENC, StringUtils.getBytes((String) key, enc));
            lb.writeBytes(StringSelfDataType.STRING_LENENC, StringUtils.getBytes(props.getProperty((String) key), enc));
        }

        buf.writeInteger(IntegerDataType.INT_LENENC, lb.getPosition());
        buf.writeBytes(StringLengthDataType.STRING_FIXED, lb.getByteBuffer(), 0, lb.getPosition());
    }
 
Example 11
public static Map<String, String> getSystemProperties(File propertiesFile) {
    Map<String, String> propertyMap = new HashMap<String, String>();
    if (!propertiesFile.isFile()) {
        return propertyMap;
    }
    Properties properties = new Properties();
    try {
        FileInputStream inStream = new FileInputStream(propertiesFile);
        try {
            properties.load(inStream);
        } finally {
            inStream.close();
        }
    } catch (IOException e) {
        throw new RuntimeException("Error when loading properties file=" + propertiesFile, e);
    }

    Pattern pattern = Pattern.compile("systemProp\\.(.*)");
    for (Object argument : properties.keySet()) {
        Matcher matcher = pattern.matcher(argument.toString());
        if (matcher.find()) {
            String key = matcher.group(1);
            if (key.length() > 0) {
                propertyMap.put(key, properties.get(argument).toString());
            }
        }
    }
    return propertyMap;
}
 
Example 12
Source Project: olat   File: TranslationDevManager.java    License: Apache License 2.0 5 votes vote down vote up
public void movePackageByMovingSingleKeysTask(String originBundleName, String targetBundleName) {
    Properties properties = i18nMgr.getPropertiesWithoutResolvingRecursively(I18nModule.getFallbackLocale(), originBundleName);
    Set<Object> keys = properties.keySet();
    for (Object keyObj : keys) {
        String key = (String) keyObj;
        moveKeyToOtherBundle(originBundleName, targetBundleName, key);
    }
}
 
Example 13
Source Project: rocketmq-4.3.0   File: Configuration.java    License: Apache License 2.0 5 votes vote down vote up
private void mergeIfExist(Properties from, Properties to) {
        for (Object key : from.keySet()) {
            if (!to.containsKey(key)) {
                continue;
            }

            Object fromObj = from.get(key), toObj = to.get(key);
            if (toObj != null && !toObj.equals(fromObj)) {
                log.info("Replace, key: {}, value: {} -> {}", key, toObj, fromObj);
            }
//            如果key值存在则替换
            to.put(key, fromObj);
        }
    }
 
Example 14
private static void dumpProperties() {

        Properties properties = System.getProperties();
        System.out.println("Total properties: " + properties.size());
        for (Object k : properties.keySet()) {
            System.out.println(k + " : " + System.getProperty((String) k));
        }
    }
 
Example 15
Source Project: big-c   File: TestRestClientBindings.java    License: Apache License 2.0 5 votes vote down vote up
public void expectBindingFailure(URI fsURI, Configuration config) {
  try {
    Properties binding = RestClientBindings.bind(fsURI, config);
    //if we get here, binding didn't fail- there is something else.
    //list the properties but not the values.
    StringBuilder details = new StringBuilder() ;
    for (Object key: binding.keySet()) {
      details.append(key.toString()).append(" ");
    }
    fail("Expected a failure, got the binding [ "+ details+"]");
  } catch (SwiftConfigurationException expected) {

  }
}
 
Example 16
@Override
public void initializeDefaultPreferences() {
	File configFile = findServerConfigFile();
	if (configFile == null)
		return;
	Properties props = readProperties(configFile);
	if (props == null)
		return;
	//load configuration preferences into the default scope
	IEclipsePreferences node = DefaultScope.INSTANCE.getNode(ServerConstants.PREFERENCE_SCOPE);
	for (Object o : props.keySet()) {
		String key = (String) o;
		node.put(key, props.getProperty(key));
	}
}
 
Example 17
Source Project: pra   File: Param.java    License: MIT License 5 votes vote down vote up
/**
 * All the parameters for all classes will be overwritten 
 * by the parameters in conf
 * @param confFile
 */
public static void overwriteFrom1(String confFile){
	Properties p = new Properties();
	try {
		p.load(new FileInputStream(confFile));
	} catch (Exception e) {
		//log.warn( "Could not load .conf at "+ conf );
		//e.printStackTrace();
	}
	for (Object s: p.keySet())
		ms.put((String) s, (String) p.get(s));		
}
 
Example 18
Source Project: wpcleaner   File: CWToolsPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Action called when Load Selection button is pressed.
 */
public void actionLoadSelection() {

  // Retrieve possible selections
  Configuration config = Configuration.getConfiguration();
  Properties properties = config.getProperties(null, Configuration.ARRAY_CHECK_BOT_SELECTION);
  if ((properties == null) || (properties.isEmpty())) {
    return;
  }
  Set<Object> keySet = properties.keySet();
  List<String> keyList = new ArrayList<String>();
  for (Object key : keySet) {
    keyList.add(key.toString());
  }
  Collections.sort(keyList);

  // Create menu
  JPopupMenu menu = new JPopupMenu();
  for (String name : keyList) {
    JMenuItem item = Utilities.createJMenuItem(name, true);
    item.setActionCommand(properties.getProperty(name));
    item.addActionListener(EventHandler.create(
        ActionListener.class, this, "actionLoadSelection", "actionCommand"));
    menu.add(item);
  }
  menu.show(
      buttonLoadSelection,
      0,
      buttonLoadSelection.getHeight());
}
 
Example 19
/**
 * Generate the help file including all of the tips
 *
 * @param parmas
 */
public static void main(String[] parmas) {
    Properties props = new Properties();
    File f = new File("src/org/zaproxy/zap/extension/tips/resources/Messages.properties");
    try {
        props.load(new FileReader(f));

        File helpFile =
                new File(
                        "src/org/zaproxy/zap/extension/tips/resources/help/contents/tips.html");
        FileWriter fw = new FileWriter(helpFile);

        fw.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n");
        fw.write("<HTML>\n");
        fw.write("<HEAD>\n");
        fw.write("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">\n");
        fw.write("<TITLE>\n");
        fw.write("Tips and Tricks\n");
        fw.write("</TITLE>\n");
        fw.write("</HEAD>\n");
        fw.write("<BODY BGCOLOR=\"#ffffff\">\n");
        fw.write("<H1>Tips and Tricks</H1>\n");
        fw.write("<!-- Note that this file is generated by ExtensionTipsAndTricks-->\n");
        fw.write(
                "This add-on adds a 'help' menu item which displays useful ZAP tips and tricks.<br>\n");
        fw.write("Tips are also shown in the splash screen on start up.\n");
        fw.write("<H2>Full list of tips</H2>\n");

        Set<Object> keys = props.keySet();
        List<String> list = new ArrayList<String>();
        for (Object key : keys) {
            if (key.toString().startsWith(TIPS_PREFIX)) {
                list.add(props.getProperty(key.toString()));
            }
        }
        Collections.sort(list);
        for (String tip : list) {
            fw.write("\n<p>" + tip.replace("\n", "<br>\n") + " </p>\n\n");
        }

        fw.write("</BODY>\n");
        fw.write("</HTML>\n");
        fw.close();

        System.out.println("Help file generated: " + helpFile.getAbsolutePath());

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 20
@Override
public void init() throws Exception {
  Configuration conf = new Configuration();
  GenericOptionsParser parser = new GenericOptionsParser(conf, args);
  String[] remainingArgs = parser.getRemainingArgs();
  properties = new Properties();
  if (remainingArgs.length != 2) {
    List<String> argsList = new ArrayList<>();
    for (String arg : remainingArgs) {
      argsList.add("'" + arg + "'");
    }
    throw new IllegalArgumentException("Error expected properties-file java-opts got: " + argsList);
  }
  String propertiesFile = remainingArgs[0];
  String javaOpts = remainingArgs[1];
  try (InputStream in = new FileInputStream(propertiesFile)) {
    properties.load(in);
    String dataFormat = Utils.getHdfsDataFormat(properties);
    String source = this.getClass().getSimpleName();
    for (Object key : properties.keySet()) {
      String realKey = String.valueOf(key);
      String value = Utils.getPropertyNotNull(properties, realKey);
      conf.set(realKey, value, source);
    }
    Integer mapMemoryMb = getMapMemoryMb(javaOpts, conf);
    if (mapMemoryMb != null) {
      conf.set(MAPREDUCE_MAP_MEMORY_MB, String.valueOf(mapMemoryMb));
    }
    conf.set(MAPREDUCE_JAVA_OPTS, javaOpts);
    conf.setBoolean("mapreduce.map.speculative", false);
    conf.setBoolean("mapreduce.reduce.speculative", false);
    if ("AVRO".equalsIgnoreCase(dataFormat)) {
      conf.set(Job.INPUT_FORMAT_CLASS_ATTR, "org.apache.avro.mapreduce.AvroKeyInputFormat");
      conf.set(Job.MAP_OUTPUT_KEY_CLASS, "org.apache.avro.mapred.AvroKey");
    }
    job = Job.getInstance(conf, "StreamSets Data Collector: " + properties.getProperty(ClusterModeConstants.CLUSTER_PIPELINE_TITLE));
    job.setJarByClass(this.getClass());
    job.setNumReduceTasks(0);
    if (!"AVRO".equalsIgnoreCase(dataFormat)) {
      job.setOutputKeyClass(NullWritable.class);
    }
    job.setMapperClass(PipelineMapper.class);

    job.setOutputValueClass(NullWritable.class);

    job.setOutputFormatClass(NullOutputFormat.class);
  }
}