Java Code Examples for com.google.common.collect.Maps#fromProperties()

The following examples show how to use com.google.common.collect.Maps#fromProperties() . 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: PrestoDriverUri.java    From presto with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: BuildInfo.java    From attic-aurora with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example 3
Source File: MapsExample.java    From levelup-java-examples with Apache License 2.0 6 votes vote down vote up
/**
 * 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"));

}
 
Example 4
Source File: ConvertPropertiesToMap.java    From levelup-java-examples with Apache License 2.0 6 votes vote down vote up
@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"));
}
 
Example 5
Source File: ConfigKit.java    From jfinal-ext3 with Apache License 2.0 5 votes vote down vote up
/**
 * @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!");
}
 
Example 6
Source File: CatalogManager.java    From metacat with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: AuthScopeRepository.java    From endpoints-java with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 8
Source File: DeploymentConfigurationService.java    From render with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example 9
Source File: DruidSinkIT.java    From ingestion with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 10
Source File: FilterResourcesProcessor.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
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);
}
 
Example 11
Source File: LegacyClientDelegate.java    From tajo with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 12
Source File: LegacyClientDelegate.java    From tajo with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 13
Source File: DiagnosticManagerImpl.java    From seed with Mozilla Public License 2.0 4 votes vote down vote up
private Map<String, String> buildSystemPropertiesList() {
    return Maps.fromProperties(System.getProperties());
}
 
Example 14
Source File: TableDataInserter.java    From HiveRunner with Apache License 2.0 4 votes vote down vote up
TableDataInserter(String databaseName, String tableName, HiveConf conf) {
  this.databaseName = databaseName;
  this.tableName = tableName;
  config = Maps.fromProperties(conf.getAllProperties());
}
 
Example 15
Source File: LogicalPlanConfiguration.java    From Bats with Apache License 2.0 2 votes vote down vote up
/**
 * Properties for the node. Template values (if set) become property defaults.
 *
 * @return Map<String,String>
 */
private Map<String, String> getProperties()
{
  return Maps.fromProperties(properties);
}
 
Example 16
Source File: LogicalPlanConfiguration.java    From attic-apex-core with Apache License 2.0 2 votes vote down vote up
/**
 * Properties for the node. Template values (if set) become property defaults.
 *
 * @return Map<String,String>
 */
private Map<String, String> getProperties()
{
  return Maps.fromProperties(properties);
}