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.xiaomo.TimeMachine.kit.ResourceKit.java

public static Map<String, String> readProperties(String resourceName) {
    Properties properties = new Properties();
    URL resource = Resources.getResource(resourceName);
    try {/* w ww .j av  a 2s .  c om*/
        properties.load(new InputStreamReader(resource.openStream(), "UTF-8"));
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    return Maps.fromProperties(properties);
}

From source file:com.enonic.cms.core.config.ConfigProperties.java

public Map<String, String> getMap() {
    return Maps.fromProperties(this);
}

From source file:com.google.caliper.worker.handler.HostDevice.java

/** Gets a selection of properties about the device this worker is running on. */
static Map<String, String> getProperties() {
    TreeMap<String, String> propertyMap = Maps.newTreeMap();

    Map<String, String> sysProps = Maps.fromProperties(System.getProperties());

    // Sometimes java.runtime.version is more descriptive than java.version
    String version = sysProps.get("java.version");
    String alternateVersion = sysProps.get("java.runtime.version");
    if (alternateVersion != null && alternateVersion.length() > version.length()) {
        version = alternateVersion;//from  w w  w.jav a  2  s  . c om
    }
    propertyMap.put("host.availableProcessors", Integer.toString(Runtime.getRuntime().availableProcessors()));

    String osName = sysProps.get("os.name");
    propertyMap.put("os.name", osName);
    propertyMap.put("os.version", sysProps.get("os.version"));
    propertyMap.put("os.arch", sysProps.get("os.arch"));

    if (osName.equals("Linux")) {
        getLinuxEnvironment(propertyMap);
    }

    return propertyMap;
}

From source file:org.opendaylight.tsdr.spi.util.ConfigFileUtil.java

public static Map<String, String> loadConfig(String config) throws IOException {
    Properties properties = new Properties();
    properties.load(Files.asCharSource(new File(config), Charsets.UTF_8).openStream());
    return Maps.fromProperties(properties);
}

From source file:dk.ilios.spanner.bridge.VmPropertiesLogMessage.java

public VmPropertiesLogMessage() {
    this(ImmutableMap.copyOf(Maps.fromProperties(System.getProperties())));
}

From source file:com.iblsoft.iwxxm.webservice.config.ConfigManager.java

private static void init() {
    Properties systemProperties = System.getProperties();
    Map<String, String> environmentProperties = System.getenv();
    String configRootDir = getConfigDirectoryRootPath();

    globalProperties = new HashMap<>();
    globalProperties.putAll(Maps.fromProperties(systemProperties));
    globalProperties.putAll(environmentProperties);
    globalProperties.put("configDir", configRootDir);

    for (Map.Entry<String, String> entry : globalProperties.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        ConfigFactory.setProperty(key, value);
    }// ww  w. j a v a2s.  c  o  m
}

From source file:org.sonar.core.persistence.DaoTestCase.java

@BeforeClass
public static void startDatabase() throws Exception {
    Settings settings = new Settings();
    settings.setProperties(Maps.fromProperties(System.getProperties()));
    if (settings.hasKey("sonar.jdbc.dialect")) {
        database = new DefaultDatabase(settings);
    } else {/*from w ww .ja  v a 2  s.  c o  m*/
        database = new InMemoryDatabase();
    }
    database.start();

    myBatis = new MyBatis(database);
    myBatis.start();

    databaseCommands = DatabaseCommands.forDialect(database.getDialect());
}

From source file:org.lendingclub.mercator.core.BasicProjector.java

private void collectConfig() {
    properties = Maps.newHashMap();// w w  w. j a va  2s. c o  m
    properties.putAll(Maps.fromProperties(System.getProperties()));

    File projectorPropertiesFile = new File("./mercator.properties");
    if (projectorPropertiesFile.exists()) {
        try (FileReader fr = new FileReader(projectorPropertiesFile)) {
            Properties p = new Properties();
            p.load(fr);
            properties.putAll(properties);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:com.google.caliper.runner.EnvironmentGetter.java

private Map<String, String> getProperties() {
    TreeMap<String, String> propertyMap = Maps.newTreeMap();

    Map<String, String> sysProps = Maps.fromProperties(System.getProperties());

    // Sometimes java.runtime.version is more descriptive than java.version
    String version = sysProps.get("java.version");
    String alternateVersion = sysProps.get("java.runtime.version");
    if (alternateVersion != null && alternateVersion.length() > version.length()) {
        version = alternateVersion;/*www.  j  a  va2s  . c om*/
    }
    propertyMap.put("host.availableProcessors", Integer.toString(Runtime.getRuntime().availableProcessors()));

    String osName = sysProps.get("os.name");
    propertyMap.put("os.name", osName);
    propertyMap.put("os.version", sysProps.get("os.version"));
    propertyMap.put("os.arch", sysProps.get("os.arch"));

    if (osName.equals("Linux")) {
        getLinuxEnvironment(propertyMap);
    }

    return propertyMap;
}

From source file:com.google.caliper.util.Util.java

public static ImmutableMap<String, String> loadProperties(ByteSource is) throws IOException {
    Properties props = new Properties();
    Closer closer = Closer.create();/*from ww  w  . j  a  va  2 s .c o  m*/
    InputStream in = closer.register(is.openStream());
    try {
        props.load(in);
    } finally {
        closer.close();
    }
    return Maps.fromProperties(props);
}