List of usage examples for com.google.common.collect Maps fromProperties
@GwtIncompatible("java.util.Properties") public static ImmutableMap<String, String> fromProperties(Properties properties)
From source file:io.prestosql.jdbc.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)); }/* w ww . j a va 2 s . c o m*/ } Properties result = new Properties(); setProperties(result, defaults); setProperties(result, urlProperties); setProperties(result, suppliedProperties); return result; }
From source file:org.kiji.schema.impl.hbase.HBaseSystemTable.java
/** * Loads a map of properties from the properties file named by resource. * * @param resource The name of the properties resource holding the defaults. * @return The properties in the file as a Map. * @throws IOException If there is an error. *///from w ww .j a v a 2 s.com public static Map<String, String> loadPropertiesFromFileToMap(String resource) throws IOException { final Properties defaults = new Properties(); defaults.load(HBaseSystemTable.class.getClassLoader().getResourceAsStream(resource)); return Maps.fromProperties(defaults); }
From source file:com.github.charithe.kafka.EphemeralKafkaBroker.java
/** * Create a producer that can write to this broker * * @param keySerializer Key serializer class * @param valueSerializer Valuer serializer class * @param overrideConfig Producer config to override. Pass null if there aren't any. * @param <K> Type of Key * @param <V> Type of Value * @return KafkaProducer//from w ww . java2 s . c o m */ public <K, V> KafkaProducer<K, V> createProducer(Serializer<K> keySerializer, Serializer<V> valueSerializer, Properties overrideConfig) { Properties conf = producerConfig(); if (overrideConfig != null) { conf.putAll(overrideConfig); } keySerializer.configure(Maps.fromProperties(conf), true); valueSerializer.configure(Maps.fromProperties(conf), false); return new KafkaProducer<>(conf, keySerializer, valueSerializer); }
From source file:com.ariht.maven.plugins.config.generator.ConfigGeneratorImpl.java
/** * Compile list of every property in all filter io - used to provide dummy values * in missing properties identified in set difference check. *//*w w w . j a v a 2s. c om*/ private Set<String> getAllProperties(List<FileInfo> filters) throws ConfigurationException, IOException { final Set<String> allProperties = new LinkedHashSet<String>(); for (final FileInfo filter : filters) { final Properties properties = readFilterIntoProperties(filter); final ImmutableMap<String, String> valueMap = Maps.fromProperties(properties); allProperties.addAll(valueMap.keySet()); } return allProperties; }
From source file:com.github.charithe.kafka.EphemeralKafkaBroker.java
/** * Create a consumer that can read from this broker * * @param keyDeserializer Key deserializer * @param valueDeserializer Value deserializer * @param overrideConfig Consumer config to override. Pass null if there aren't any * @param <K> Type of Key * @param <V> Type of Value * @return KafkaConsumer/*from w w w. ja v a 2s . c o m*/ */ public <K, V> KafkaConsumer<K, V> createConsumer(Deserializer<K> keyDeserializer, Deserializer<V> valueDeserializer, Properties overrideConfig) { Properties conf = consumerConfig(); if (overrideConfig != null) { conf.putAll(overrideConfig); } keyDeserializer.configure(Maps.fromProperties(conf), true); valueDeserializer.configure(Maps.fromProperties(conf), false); return new KafkaConsumer<>(conf, keyDeserializer, valueDeserializer); }
From source file:fr.inria.atlanmod.neoemf.benchmarks.datastore.helper.BackendHelper.java
private static Map<String, String> getRegisteredResources() throws IOException { if (isNull(REGISTERED_RESOURCES)) { Properties properties = new Properties(); properties.load(BackendHelper.class.getResourceAsStream("/resources.properties")); REGISTERED_RESOURCES = Maps.fromProperties(properties); }// w w w.j av a 2 s.c om return REGISTERED_RESOURCES; }
From source file:org.dcache.alarms.logback.LogEntryAppender.java
private void initPersistenceManagerFactory() throws IOException { Properties properties = new Properties(); if (propertiesPath != null && !propertiesPath.trim().isEmpty()) { File file = new File(propertiesPath); if (!file.exists()) { throw new FileNotFoundException(file.getAbsolutePath()); }//from w w w . j a va2s . com try (InputStream stream = new FileInputStream(file)) { properties.load(stream); } } if (url.startsWith("xml:")) { initializeXmlFile(path); properties.setProperty("datanucleus.ConnectionURL", url); } else if (url.startsWith("jdbc:")) { HikariConfig config = new HikariConfig(); config.setDataSource(new DriverManagerDataSource(url, user, password)); dataSource = new HikariDataSource(config); properties.setProperty("datanucleus.connectionPoolingType", "None"); } pmf = new JDOPersistenceManagerFactory(Maps.<String, Object>newHashMap(Maps.fromProperties(properties))); if (dataSource != null) { pmf.setConnectionFactory(dataSource); } }
From source file:com.dangdang.config.service.web.mb.PropertyGroupManagedBean.java
@Deprecated private void savePropertyGroupOld(String fileName, String group, InputStream inputstream) throws IOException { Reader reader = new InputStreamReader(inputstream, Charsets.UTF_8); Properties properties = new Properties(); properties.load(reader);//from w w w .ja v a2 s . com if (!properties.isEmpty()) { String authedNode = ZKPaths.makePath(nodeAuth.getAuthedNode(), versionMB.getSelectedVersion()); String groupPath = ZKPaths.makePath(authedNode, group); boolean created = nodeService.createProperty(groupPath, null); if (created) { Map<String, String> map = Maps.fromProperties(properties); for (Entry<String, String> entry : map.entrySet()) { nodeService.createProperty(ZKPaths.makePath(groupPath, entry.getKey()), entry.getValue()); } refreshGroup(); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Succesful", fileName + " is uploaded.")); } else { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Create group with file error.", fileName)); } } else { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "File is empty.", fileName)); } }
From source file:org.apache.oozie.util.Instrumentation.java
/** * Return the JVM system properties./*w w w. j av a2s. c o m*/ * * @return JVM system properties. */ public Map<String, String> getJavaSystemProperties() { Map<String, String> unmasked = Maps.fromProperties(System.getProperties()); return new PasswordMasker().mask(unmasked); }
From source file:cpw.mods.fml.common.Loader.java
private void disableRequestedMods() { String forcedModList = System.getProperty("fml.modStates", ""); FMLLog.finer("Received a system property request \'%s\'", forcedModList); Map<String, String> sysPropertyStateList = Splitter.on(CharMatcher.anyOf(";:")).omitEmptyStrings() .trimResults().withKeyValueSeparator("=").split(forcedModList); FMLLog.finer("System property request managing the state of %d mods", sysPropertyStateList.size()); Map<String, String> modStates = Maps.newHashMap(); forcedModFile = new File(canonicalConfigDir, "fmlModState.properties"); Properties forcedModListProperties = new Properties(); if (forcedModFile.exists() && forcedModFile.isFile()) { FMLLog.finer("Found a mod state file %s", forcedModFile.getName()); try {/* ww w. j av a2s .com*/ forcedModListProperties.load(new FileReader(forcedModFile)); FMLLog.finer("Loaded states for %d mods from file", forcedModListProperties.size()); } catch (Exception e) { FMLLog.log(Level.INFO, e, "An error occurred reading the fmlModState.properties file"); } } modStates.putAll(Maps.fromProperties(forcedModListProperties)); modStates.putAll(sysPropertyStateList); FMLLog.fine("After merging, found state information for %d mods", modStates.size()); Map<String, Boolean> isEnabled = Maps.transformValues(modStates, new Function<String, Boolean>() { @Override public Boolean apply(String input) { return Boolean.parseBoolean(input); } }); for (Map.Entry<String, Boolean> entry : isEnabled.entrySet()) { if (namedMods.containsKey(entry.getKey())) { FMLLog.info("Setting mod %s to enabled state %b", entry.getKey(), entry.getValue()); namedMods.get(entry.getKey()).setEnabledState(entry.getValue()); } } }