Example usage for com.google.common.collect Maps fromProperties

List of usage examples for com.google.common.collect Maps fromProperties

Introduction

In this page you can find the example usage for com.google.common.collect Maps fromProperties.

Prototype

@GwtIncompatible("java.util.Properties")
public static ImmutableMap<String, String> fromProperties(Properties properties) 

Source Link

Document

Creates an ImmutableMap from a Properties instance.

Usage

From source file:com.flaptor.util.Config.java

public Map<String, String> asMap() {
    return Maps.fromProperties(prop);
}

From source file:org.opennms.features.newts.converter.NewtsConverter.java

private void processStringsProperties(final Path path) {
    try {/*from   w ww  .  j  a va2  s .  c om*/
        // Find an process all 'strings.properties' files
        Files.walk(path).filter(p -> p.endsWith("strings.properties")).forEach(p -> {
            final Properties properties = new Properties();
            try (final BufferedReader r = Files.newBufferedReader(p)) {
                properties.load(r);

            } catch (final IOException e) {
                throw Throwables.propagate(e);
            }

            final ResourcePath resourcePath = buildResourcePath(p.getParent());
            if (resourcePath == null) {
                return;
            }

            this.injectStringPropertiesToNewts(resourcePath, Maps.fromProperties(properties));
        });

    } catch (Exception e) {
        LOG.error("Error while reading string.properties", e);
        return;
    }
}

From source file:org.apache.hive.hcatalog.common.HCatUtil.java

public static Map<String, String> getHCatKeyHiveConf(JobConf conf) {
    try {//from   w  ww  .  jav  a2s  . c  om
        Properties properties = null;

        if (!StringUtils.isBlank(conf.get(HCatConstants.HCAT_KEY_HIVE_CONF))) {
            properties = (Properties) HCatUtil.deserialize(conf.get(HCatConstants.HCAT_KEY_HIVE_CONF));

            LOG.info(HCatConstants.HCAT_KEY_HIVE_CONF + " is set. Using differences=" + properties);
        } else {
            LOG.info(HCatConstants.HCAT_KEY_HIVE_CONF + " not set. Generating configuration differences.");

            properties = getHiveSiteOverrides(conf);
        }

        // This method may not be safe as it can throw an NPE if a key or value is null.
        return Maps.fromProperties(properties);
    } catch (IOException e) {
        throw new IllegalStateException("Failed to deserialize hive conf", e);
    }
}

From source file:cpw.mods.fml.common.Loader.java

public Map<String, String> getFMLBrandingProperties() {
    if (fmlBrandingProperties == null) {
        Properties loaded = new Properties();
        try {/* ww w  .  j  a v  a2s.  com*/
            loaded.load(getClass().getClassLoader().getResourceAsStream("fmlbranding.properties"));
        } catch (Exception e) {
            // File not found - ignore
        }
        fmlBrandingProperties = Maps.fromProperties(loaded);
    }
    return fmlBrandingProperties;
}

From source file:com.datatorrent.stram.plan.logical.LogicalPlanConfiguration.java

private Map<String, String> getApplicationProperties(List<AppConf> appConfs) {
    Map<String, String> appProps = Maps.newHashMap();
    // Apply the configurations in reverse order since the higher priority ones are at the beginning
    for (int i = appConfs.size() - 1; i >= 0; i--) {
        AppConf conf1 = appConfs.get(i);
        appProps.putAll(Maps.fromProperties(conf1.properties));
    }//from w  ww.  j  a v a2  s .  c  om
    return appProps;
}

From source file:com.datatorrent.stram.plan.logical.LogicalPlanConfiguration.java

/**
 * Get the configuration opProps for the given operator.
 * These can be operator specific settings or settings from matching templates.
 * @param pa/*  www.  j  a  va  2  s . com*/
 * @param opConfs
 * @param appName
 */
private Map<String, String> getProperties(PropertyArgs pa, List<OperatorConf> opConfs, String appName) {
    Map<String, String> opProps = Maps.newHashMap();
    Map<String, TemplateConf> templates = stramConf.getChildren(StramElement.TEMPLATE);
    // list of all templates that match operator, ordered by priority
    if (!templates.isEmpty()) {
        TreeMap<Integer, TemplateConf> matchingTemplates = getMatchingTemplates(pa, appName, templates);
        if (matchingTemplates != null && !matchingTemplates.isEmpty()) {
            // combined map of prioritized template settings
            for (TemplateConf t : matchingTemplates.descendingMap().values()) {
                opProps.putAll(Maps.fromProperties(t.properties));
            }
        }

        List<TemplateConf> refTemplates = getDirectTemplates(opConfs, templates);
        for (TemplateConf t : refTemplates) {
            opProps.putAll(Maps.fromProperties(t.properties));
        }
    }
    // direct settings
    // Apply the configurations in reverse order since the higher priority ones are at the beginning
    for (int i = opConfs.size() - 1; i >= 0; i--) {
        Conf conf1 = opConfs.get(i);
        opProps.putAll(Maps.fromProperties(conf1.properties));
    }
    return opProps;
}