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

The following examples show how to use java.util.Properties#keySet() . 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 File: Bazel.java    From bazel with 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 2
Source File: SystemPropertiesViewSupport.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
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 File: GetBrokerConfigCommand.java    From DDMQ with 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 4
Source File: SystemPropertiesHandler.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 5
Source File: CWToolsPanel.java    From wpcleaner with 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 6
Source File: Param.java    From pra with 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 7
Source File: OrionPreferenceInitializer.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@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 8
Source File: TestRestClientBindings.java    From big-c with 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 9
Source File: WriteOnceProperties.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 10
Source File: Configuration.java    From rocketmq-4.3.0 with 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 11
Source File: TranslationDevManager.java    From olat with 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 12
Source File: MicroIntegratorRegistry.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@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 13
Source File: NativeAuthenticationProvider.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 14
Source File: Configuration.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
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 15
Source File: ReduceEstimator.java    From datafu with 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 16
Source File: PlatformUtil.java    From common-project with 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 17
Source File: LdapSettingsManagementServiceBean.java    From development with Apache License 2.0 5 votes vote down vote up
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 18
Source File: DefaultEnvironmentPostProcessor.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
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 19
Source File: HadoopMapReduceBinding.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@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);
  }
}
 
Example 20
Source File: ExtensionTipsAndTricks.java    From zap-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * 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();
    }
}