com.google.common.collect.Maps#fromProperties ( )源码实例Demo

下面列出了com.google.common.collect.Maps#fromProperties ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: presto   文件: PrestoDriverUri.java
private static Properties mergeConnectionProperties(URI uri, Properties driverProperties)
        throws SQLException
{
    Map<String, String> defaults = ConnectionProperties.getDefaults();
    Map<String, String> urlProperties = parseParameters(uri.getQuery());
    Map<String, String> suppliedProperties = Maps.fromProperties(driverProperties);

    for (String key : urlProperties.keySet()) {
        if (suppliedProperties.containsKey(key)) {
            throw new SQLException(format("Connection property '%s' is both in the URL and an argument", key));
        }
    }

    Properties result = new Properties();
    setProperties(result, defaults);
    setProperties(result, urlProperties);
    setProperties(result, suppliedProperties);
    return result;
}
 
源代码2 项目: attic-aurora   文件: BuildInfo.java
private void fetchProperties() {
  LOG.info("Fetching build properties from " + resourcePath);
  InputStream in = ClassLoader.getSystemResourceAsStream(resourcePath);
  if (in == null) {
    LOG.warn("Failed to fetch build properties from " + resourcePath);
    return;
  }

  try {
    Properties buildProperties = new Properties();
    buildProperties.load(in);
    properties = Maps.fromProperties(buildProperties);
  } catch (Exception e) {
    LOG.warn("Failed to load properties file " + resourcePath, e);
  }
}
 
源代码3 项目: levelup-java-examples   文件: MapsExample.java
/**
 * Convert properties to map
 */
@Test
public void map_of_properties() {

	Properties properties = new Properties();
	properties.put("leveluplunch.java.examples",
			"http://www.leveluplunch.com/java/examples/");
	properties.put("leveluplunch.java.exercises",
			"http://www.leveluplunch.com/java/exercises/");
	properties.put("leveluplunch.java.tutorials",
			"http://www.leveluplunch.com/java/tutorials/");

	Map<String, String> mapOfProperties = Maps.fromProperties(properties);

	logger.info(mapOfProperties);

	assertThat(mapOfProperties, hasKey("leveluplunch.java.examples"));

}
 
@Test
public void create_map_from_properties_guava() {

	Properties properties = new Properties();
	properties.put("database.username", "yourname");
	properties.put("database.password", "encrypted_password");
	properties.put("database.driver", "com.mysql.jdbc.Driver");
	properties.put("database.url",
			"jdbc:mysql://localhost:3306/sakila?profileSQL=true");

	Map<String, String> mapOfProperties = Maps.fromProperties(properties);

	logger.info(mapOfProperties);

	assertThat(
			mapOfProperties.keySet(),
			containsInAnyOrder("database.username", "database.password",
					"database.driver", "database.url"));
}
 
源代码5 项目: jfinal-ext3   文件: ConfigKit.java
/**
 * @param includeResources
 * @param excludeResources
 * @param reload
 */
static void init(List<String> includeResources, List<String> excludeResources, boolean reload) {
    ConfigKit.includeResources = includeResources;
    ConfigKit.excludeResources = excludeResources;
    ConfigKit.reload = reload;
    for (final String resource : includeResources) {
    LOG.debug("include :" + resource);
        File[] propertiesFiles = new File(PathKit.getRootClassPath()).listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                return Pattern.compile(resource).matcher(pathname.getName()).matches();
            }
            
        });
        for (File file : propertiesFiles) {
            String fileName = file.getName();
            LOG.debug("fileName:" + fileName);
            boolean excluded = false;
            for (String exclude : excludeResources) {
                if (Pattern.compile(exclude).matcher(file.getName()).matches()) {
                    excluded = true;
                }
            }
            if (excluded) {
                continue;
            }
            lastmodifies.put(fileName, new File(fileName).lastModified());
            Map<String, String> mapData = Maps.fromProperties(new Prop(fileName).getProperties());
            map.putAll(mapData);
        }
    }
    LOG.debug("map" + map);
    LOG.info("config init success!");
}
 
源代码6 项目: metacat   文件: CatalogManager.java
private Map<String, String> loadProperties(final File file)
    throws Exception {
    Preconditions.checkNotNull(file, "file is null");

    final Properties properties = new Properties();
    try (FileInputStream in = new FileInputStream(file)) {
        properties.load(in);
    }
    return Maps.fromProperties(properties);
}
 
源代码7 项目: endpoints-java   文件: AuthScopeRepository.java
private static ImmutableMap<String, String> loadScopeDescriptions(String fileName) {
  try {
    Properties properties = new Properties();
    URL resourceFile = Resources.getResource(DiscoveryGenerator.class, fileName);
    InputStream inputStream = resourceFile.openStream();
    properties.load(inputStream);
    inputStream.close();
    return Maps.fromProperties(properties);
  } catch (IOException e) {
    throw new IllegalStateException("Cannot load scope descriptions from " + fileName, e);
  }
}
 
源代码8 项目: render   文件: DeploymentConfigurationService.java
@Path("v1/versionInfo")
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
        tags = "Service Configuration APIs",
        value = "The build version information for deployed services")
public Map<String, String> getVersionInfo() {

    if (versionInfo == null) {
        // load version info created by maven build process if it is available
        try {
            final InputStream infoStream = getClass().getClassLoader().getResourceAsStream("git.properties");
            if (infoStream != null) {
                final Properties p = new Properties();
                p.load(infoStream);

                // add commit URL to make it easier to cut-and-paste into a browser
                final String remoteOriginUrl = p.getProperty("git.remote.origin.url");
                final String commitId = p.getProperty("git.commit.id");
                if ((remoteOriginUrl != null) && (commitId != null)) {
                    p.setProperty("git.commit.url", String.format("%s/commit/%s", remoteOriginUrl, commitId));
                }

                versionInfo = Maps.fromProperties(p);

                LOG.info("getVersionInfo: loaded version info");
            }
        } catch (final Throwable t) {
            LOG.warn("getVersionInfo: failed to load version info", t);
        }
    }

    return versionInfo;
}
 
源代码9 项目: ingestion   文件: DruidSinkIT.java
private Map<String, String> loadProperties(String file) {
    Properties properties = new Properties();
    try {
        properties.load(getClass().getResourceAsStream(file));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return Maps.fromProperties(properties);
}
 
private static Map<String, String> readProperties(File file) {
  Properties properties = new Properties();
  try (InputStream is = new FileInputStream(file)) {
    properties.load(is);
  } catch (IOException e) {
    // too bad
  }
  return Maps.fromProperties(properties);
}
 
源代码11 项目: tajo   文件: LegacyClientDelegate.java
public LegacyClientDelegate(String host, int port, Properties clientParams) {
  super(new DummyServiceTracker(NetUtils.createSocketAddr(host, port)), null,
      new KeyValueSet(clientParams == null ? new HashMap<String, String>() : Maps.fromProperties(clientParams)));
  queryClient = new QueryClientImpl(this);
}
 
源代码12 项目: tajo   文件: LegacyClientDelegate.java
public LegacyClientDelegate(ServiceDiscovery discovery, Properties clientParams) {
  super(new DelegateServiceTracker(discovery), null,
      new KeyValueSet(clientParams == null ? new HashMap<String, String>() : Maps.fromProperties(clientParams)));
  queryClient = new QueryClientImpl(this);
}
 
源代码13 项目: seed   文件: DiagnosticManagerImpl.java
private Map<String, String> buildSystemPropertiesList() {
    return Maps.fromProperties(System.getProperties());
}
 
源代码14 项目: HiveRunner   文件: TableDataInserter.java
TableDataInserter(String databaseName, String tableName, HiveConf conf) {
  this.databaseName = databaseName;
  this.tableName = tableName;
  config = Maps.fromProperties(conf.getAllProperties());
}
 
源代码15 项目: Bats   文件: LogicalPlanConfiguration.java
/**
 * Properties for the node. Template values (if set) become property defaults.
 *
 * @return Map<String,String>
 */
private Map<String, String> getProperties()
{
  return Maps.fromProperties(properties);
}
 
源代码16 项目: attic-apex-core   文件: LogicalPlanConfiguration.java
/**
 * Properties for the node. Template values (if set) become property defaults.
 *
 * @return Map<String,String>
 */
private Map<String, String> getProperties()
{
  return Maps.fromProperties(properties);
}