Java Code Examples for org.apache.commons.configuration.PropertiesConfiguration#getKeys()

The following examples show how to use org.apache.commons.configuration.PropertiesConfiguration#getKeys() . 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: MultiGraphsTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
public static HugeGraph openGraphWithBackend(String graph, String backend,
                                             String serializer,
                                             String... configs) {
    PropertiesConfiguration conf = Utils.getConf();
    Configuration config = new BaseConfiguration();
    for (Iterator<String> keys = conf.getKeys(); keys.hasNext();) {
        String key = keys.next();
        config.setProperty(key, conf.getProperty(key));
    }
    ((BaseConfiguration) config).setDelimiterParsingDisabled(true);
    config.setProperty(CoreOptions.STORE.name(), graph);
    config.setProperty(CoreOptions.BACKEND.name(), backend);
    config.setProperty(CoreOptions.SERIALIZER.name(), serializer);
    for (int i = 0; i < configs.length;) {
        config.setProperty(configs[i++], configs[i++]);
    }
    return ((HugeGraph) GraphFactory.open(config));
}
 
Example 2
Source File: Atlas.java    From atlas with Apache License 2.0 6 votes vote down vote up
private static void showStartupInfo(PropertiesConfiguration buildConfiguration, boolean enableTLS, int appPort) {
    StringBuilder buffer = new StringBuilder();
    buffer.append("\n############################################");
    buffer.append("############################################");
    buffer.append("\n                               Atlas Server (STARTUP)");
    buffer.append("\n");
    try {
        final Iterator<String> keys = buildConfiguration.getKeys();
        while (keys.hasNext()) {
            String key = keys.next();
            buffer.append('\n').append('\t').append(key).
                    append(":\t").append(buildConfiguration.getProperty(key));
        }
    } catch (Throwable e) {
        buffer.append("*** Unable to get build info ***");
    }
    buffer.append("\n############################################");
    buffer.append("############################################");
    LOG.info(buffer.toString());
    LOG.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    LOG.info("Server starting with TLS ? {} on port {}", enableTLS, appPort);
    LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
}
 
Example 3
Source File: Atlas.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private static void showStartupInfo(PropertiesConfiguration buildConfiguration, boolean enableTLS, int appPort) {
    StringBuilder buffer = new StringBuilder();
    buffer.append("\n############################################");
    buffer.append("############################################");
    buffer.append("\n                               Atlas Server (STARTUP)");
    buffer.append("\n");
    try {
        final Iterator<String> keys = buildConfiguration.getKeys();
        while (keys.hasNext()) {
            String key = keys.next();
            buffer.append('\n').append('\t').append(key).
                    append(":\t").append(buildConfiguration.getProperty(key));
        }
    } catch (Throwable e) {
        buffer.append("*** Unable to get build info ***");
    }
    buffer.append("\n############################################");
    buffer.append("############################################");
    LOG.info(buffer.toString());
    LOG.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    LOG.info("Server starting with TLS ? {} on port {}", enableTLS, appPort);
    LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
}
 
Example 4
Source File: SettingsLoader.java    From opensoc-streaming with Apache License 2.0 6 votes vote down vote up
public static void printConfigOptions(PropertiesConfiguration config, String path_fragment)
{
	Iterator<String> itr = config.getKeys();
	
	while(itr.hasNext())
	{
		String key = itr.next();
		
		if(key.contains(path_fragment))
		{
			
			System.out.println("[OpenSOC] Key: " + key + " -> " + config.getString(key));
		}
	}

}
 
Example 5
Source File: SettingsLoader.java    From opensoc-streaming with Apache License 2.0 6 votes vote down vote up
public static Map<String, String> getConfigOptions(PropertiesConfiguration config, String path_fragment)
{
	Iterator<String> itr = config.getKeys();
	Map<String, String> settings = new HashMap<String, String>();
	
	while(itr.hasNext())
	{
		String key = itr.next();
		
		if(key.contains(path_fragment))
		{
			String tmp_key = key.replace(path_fragment, "");
			settings.put(tmp_key, config.getString(key));
		}
	}

	return settings;
}
 
Example 6
Source File: Properties2HoconConverterTest.java    From wisdom with Apache License 2.0 6 votes vote down vote up
@Test
public void testOnWikipediaSample() throws IOException {
    File props = new File(root, "/wiki.properties");
    File hocon = Properties2HoconConverter.convert(props, true);

    PropertiesConfiguration properties = loadPropertiesWithApacheConfiguration(props);
    assertThat(properties).isNotNull();
    Config config = load(hocon);
    assertThat(properties.isEmpty()).isFalse();
    assertThat(config.isEmpty()).isFalse();

    Iterator<String> iterator = properties.getKeys();
    String[] names = Iterators.toArray(iterator, String.class);
    for (String name : names) {
        if (!name.isEmpty()) {
            // 'cheeses' is not supported by commons-config.
            String o = properties.getString(name);
            String v = config.getString(name);
            assertThat(o).isEqualTo(v);
        }
    }

    assertThat(config.getString("cheeses")).isEmpty();

}
 
Example 7
Source File: MultiGraphsTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public static List<HugeGraph> openGraphs(String... graphNames) {
    List<HugeGraph> graphs = new ArrayList<>(graphNames.length);
    PropertiesConfiguration conf = Utils.getConf();
    Configuration config = new BaseConfiguration();
    for (Iterator<String> keys = conf.getKeys(); keys.hasNext();) {
        String key = keys.next();
        config.setProperty(key, conf.getProperty(key));
    }
    ((BaseConfiguration) config).setDelimiterParsingDisabled(true);
    for (String graphName : graphNames) {
        config.setProperty(CoreOptions.STORE.name(), graphName);
        graphs.add((HugeGraph) GraphFactory.open(config));
    }
    return graphs;
}
 
Example 8
Source File: TestGraphProvider.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> getBaseConfiguration(
                           String graphName,
                           Class<?> testClass, String testMethod,
                           LoadGraphWith.GraphData graphData) {
    // Check if test in blackList
    String testFullName = testClass.getCanonicalName() + "." + testMethod;
    int index = testFullName.indexOf('@') == -1 ?
                testFullName.length() : testFullName.indexOf('@');

    testFullName = testFullName.substring(0, index);
    Assume.assumeFalse(
           String.format("Test %s will be ignored with reason: %s",
                         testFullName, this.blackMethods.get(testFullName)),
           this.blackMethods.containsKey(testFullName));

    LOG.debug("Full name of test is: {}", testFullName);
    LOG.debug("Prefix of test is: {}", testFullName.substring(0, index));
    HashMap<String, Object> confMap = new HashMap<>();
    PropertiesConfiguration config = Utils.getConf();
    Iterator<String> keys = config.getKeys();
    while (keys.hasNext()) {
        String key = keys.next();
        confMap.put(key, config.getProperty(key));
    }
    String storePrefix = config.getString(CoreOptions.STORE.name());
    confMap.put(CoreOptions.STORE.name(),
                storePrefix + "_" + this.suite + "_" + graphName);
    confMap.put(GREMLIN_GRAPH_KEY, GREMLIN_GRAPH_VALUE);
    confMap.put(TEST_CLASS, testClass);
    confMap.put(TEST_METHOD, testMethod);
    confMap.put(LOAD_GRAPH, graphData);
    confMap.put(EXPECT_CUSTOMIZED_ID, customizedId(testClass, testMethod));

    return confMap;
}
 
Example 9
Source File: StarTreeIndexMapUtils.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Loads the index maps for multiple star-trees from a file.
 */
public static List<Map<IndexKey, IndexValue>> loadFromFile(File indexMapFile, int numStarTrees)
    throws ConfigurationException {
  Preconditions.checkState(indexMapFile.exists(), "Star-tree index map file does not exist");

  PropertiesConfiguration configuration = new PropertiesConfiguration(indexMapFile);
  List<Map<IndexKey, IndexValue>> indexMaps = new ArrayList<>(numStarTrees);
  for (int i = 0; i < numStarTrees; i++) {
    indexMaps.add(new HashMap<>());
  }
  Iterator keys = configuration.getKeys();
  while (keys.hasNext()) {
    String key = (String) keys.next();
    String[] split = key.split("\\.");
    Preconditions.checkState(split.length == 4,
        "Invalid key: " + key + " in star-tree index map file: " + indexMapFile.getAbsolutePath());
    int starTreeId = Integer.parseInt(split[0]);
    Map<IndexKey, IndexValue> indexMap = indexMaps.get(starTreeId);
    IndexType indexType = IndexType.valueOf(split[2]);
    IndexKey indexKey;
    if (indexType == IndexType.STAR_TREE) {
      indexKey = STAR_TREE_INDEX_KEY;
    } else {
      indexKey = new IndexKey(IndexType.FORWARD_INDEX, split[1]);
    }
    IndexValue indexValue = indexMap.computeIfAbsent(indexKey, (k) -> new IndexValue());
    long value = configuration.getLong(key);
    if (split[3].equals(OFFSET_SUFFIX)) {
      indexValue._offset = value;
    } else {
      indexValue._size = value;
    }
  }
  return indexMaps;
}