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:com.netflix.metacat.main.manager.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);//from w ww .j a v a 2 s . c o m } return Maps.fromProperties(properties); }
From source file:org.obiba.onyx.spring.context.OnyxMessageSourceFactoryBean.java
protected MessageSource loadJarBundles() throws IOException { ResourcePatternResolver resolver = (ResourcePatternResolver) this.resourceLoader; String bundlePattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "META-INF/" + MESSAGES_BUNDLENAME + "*" + MESSAGES_PROPERTIES_SUFFIX; Resource[] messageResources = resolver.getResources(bundlePattern); StaticMessageSource sms = new StaticMessageSource(); for (int i = 0; i < messageResources.length; i++) { Resource resource = messageResources[i]; Locale locale = extractLocale(resource, MESSAGES_PROPERTIES_SUFFIX); log.debug("Found module bundle resource {} with locale {}", resource.getDescription(), locale); Properties props = new Properties(); props.load(resource.getInputStream()); sms.addMessages(Maps.fromProperties(props), locale); }/* w w w . j a v a2s . c o m*/ return sms; }
From source file:org.lunifera.runtime.utils.osgi.component.extender.AbstractComponentContributionHandlerServiceFactory.java
/** * Open the specified resource as a property file and put its values inside * a Map.//from ww w .j a va 2 s . c om * * @param contributionItemURL * @return * @throws Exception */ public Map<String, String> extractPropertiesFromResourceFile(URL contributionItemURL) throws ExceptionComponentExtenderSetup { Map<String, String> map; if (contributionItemURL == null) { throw new ExceptionComponentExtenderSetup("Can't process a null URL !"); } // java7 feature try (InputStream inputStream = contributionItemURL.openStream()) { Properties properties = new Properties(); properties.load(inputStream); map = Maps.fromProperties(properties); } catch (IOException e) { throw new ExceptionComponentExtenderSetup( "Error reading properties file '" + contributionItemURL.getFile() + "'.", e); } return map; }
From source file:org.geoserver.catalog.impl.CatalogPropertyAccessor.java
/** * // w w w . j a v a2 s . c om */ private static synchronized void loadFullTextProperties() { if (!FULL_TEXT_PROPERTIES.isEmpty()) { return; } final String resource = "CatalogPropertyAccessor_FullTextProperties.properties"; Properties properties = new Properties(); InputStream stream = CatalogPropertyAccessor.class.getResourceAsStream(resource); try { properties.load(stream); } catch (IOException e) { throw Throwables.propagate(e); } finally { Closeables.closeQuietly(stream); } Map<String, String> map = Maps.fromProperties(properties); for (Map.Entry<String, String> e : map.entrySet()) { Class<?> key; try { key = Class.forName(e.getKey()); } catch (ClassNotFoundException e1) { throw propagate(e1); } String[] split = e.getValue().split(","); Set<String> set = Sets.newHashSet(); for (String s : split) { set.add(s.trim()); } FULL_TEXT_PROPERTIES.put(key, ImmutableSet.copyOf(set)); } }
From source file:org.seedstack.seed.core.internal.DiagnosticManagerImpl.java
private Map<String, String> buildSystemPropertiesList() { return Maps.fromProperties(System.getProperties()); }
From source file:com.radeonsys.data.querystore.support.properties.PropertiesQueryStore.java
/** * Copies queries from the specified properties object into this query * store/*from w ww .ja v a 2 s . co m*/ * * @param props reference to an instance of {@link Properties} which * contains query definitions to copy * * @throws IllegalArgumentException * if the specified properties is {@code null} */ private final void copyQueriesToStore(Properties props) { Preconditions.checkArgument(props != null, "A valid set of properties must be specified."); if (props.isEmpty()) return; ImmutableMap<String, String> propMap = Maps.fromProperties(props); for (String queryName : propMap.keySet()) addQuery(queryName, propMap.get(queryName).trim()); if (logger.isTraceEnabled()) logger.trace(String.format("Copied %d queries into query store", props.size())); }
From source file:org.apache.tajo.cli.tsql.TajoCli.java
public TajoCli(TajoConf c, String[] args, @Nullable Properties clientParams, InputStream in, OutputStream out, OutputStream err) throws Exception { CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); this.conf = new TajoConf(c); context = new TajoCliContext(conf); this.sin = in; if (cmd.hasOption("B")) { this.reader = new ConsoleReader(sin, out, new UnsupportedTerminal()); } else {//from w ww. j av a 2s .c o m this.reader = new ConsoleReader(sin, out); } this.reader.setExpandEvents(false); this.sout = new PrintWriter(reader.getOutput()); this.serr = new PrintWriter(new OutputStreamWriter(err, "UTF-8")); initFormatter(); if (cmd.hasOption("help")) { printUsage(); System.exit(0); } String hostName = null; Integer port = null; if (cmd.hasOption("h")) { hostName = cmd.getOptionValue("h"); } if (cmd.hasOption("p")) { port = Integer.parseInt(cmd.getOptionValue("p")); } String baseDatabase = null; if (cmd.getArgList().size() > 0) { baseDatabase = (String) cmd.getArgList().get(0); } if (cmd.getOptionValues("conf") != null) { processConfVarCommand(cmd.getOptionValues("conf")); } this.reconnect = cmd.hasOption("reconnect"); // if there is no "-h" option, InetSocketAddress address = conf.getSocketAddrVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS, TajoConf.ConfVars.TAJO_MASTER_UMBILICAL_RPC_ADDRESS); if (hostName == null) { hostName = address.getHostName(); } if (port == null) { port = address.getPort(); } // Get connection parameters Properties defaultConnParams = CliClientParamsFactory.get(clientParams); final KeyValueSet actualConnParams = new KeyValueSet(Maps.fromProperties(defaultConnParams)); if ((hostName == null) ^ (port == null)) { System.err.println(ERROR_PREFIX + "cannot find valid Tajo server address"); throw new RuntimeException("cannot find valid Tajo server address"); } else if (hostName != null && port != null) { conf.setVar(ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS, NetUtils.getHostPortString(hostName, port)); client = new TajoClientImpl(ServiceTrackerFactory.get(conf), baseDatabase, actualConnParams); } else if (hostName == null && port == null) { client = new TajoClientImpl(ServiceTrackerFactory.get(conf), baseDatabase, actualConnParams); } try { context.setCurrentDatabase(client.getCurrentDatabase()); initHistory(); initCommands(); reader.addCompleter(cliCompleter); reader.addCompleter(sqlCompleter); if (cmd.getOptionValues("conf") != null) { processSessionVarCommand(cmd.getOptionValues("conf")); } if (cmd.hasOption("c")) { displayFormatter.setScriptMode(); int exitCode = executeScript(cmd.getOptionValue("c")); sout.flush(); serr.flush(); System.exit(exitCode); } if (cmd.hasOption("f")) { displayFormatter.setScriptMode(); cmd.getOptionValues(""); File sqlFile = new File(cmd.getOptionValue("f")); if (sqlFile.exists()) { String script = FileUtil.readTextFile(new File(cmd.getOptionValue("f"))); script = replaceParam(script, cmd.getOptionValues("param")); int exitCode = executeScript(script); sout.flush(); serr.flush(); System.exit(exitCode); } else { System.err.println(ERROR_PREFIX + "No such a file \"" + cmd.getOptionValue("f") + "\""); System.exit(-1); } } } catch (Exception e) { System.err.println(ERROR_PREFIX + "Exception was thrown. Caused by " + e.getMessage()); if (client != null) { client.close(); } throw e; } addShutdownHook(); }
From source file:org.kiji.schema.impl.cassandra.CassandraSystemTable.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 java.io.IOException If there is an error. *///from w w w .j a va2s . c om public static Map<String, String> loadPropertiesFromFileToMap(String resource) throws IOException { final Properties defaults = new Properties(); defaults.load(CassandraSystemTable.class.getClassLoader().getResourceAsStream(resource)); return Maps.fromProperties(defaults); }
From source file:org.apache.jackrabbit.oak.blob.cloud.aws.s3.S3Backend.java
public void init(CachingDataStore store, String homeDir, Properties prop) throws DataStoreException { ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try {/*w w w.j a va2 s .c o m*/ startTime = new Date(); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); LOG.debug("init"); this.store = store; s3ReqDecorator = new S3RequestDecorator(prop); s3service = Utils.openService(prop); if (bucket == null || "".equals(bucket.trim())) { bucket = prop.getProperty(S3Constants.S3_BUCKET); } String region = prop.getProperty(S3Constants.S3_REGION); Region s3Region = null; if (StringUtils.isNullOrEmpty(region)) { com.amazonaws.regions.Region ec2Region = Regions.getCurrentRegion(); if (ec2Region != null) { s3Region = Region.fromValue(ec2Region.getName()); } else { throw new AmazonClientException("parameter [" + S3Constants.S3_REGION + "] not configured and cannot be derived from environment"); } } else { if (Utils.DEFAULT_AWS_BUCKET_REGION.equals(region)) { s3Region = Region.US_Standard; } else if (Region.EU_Ireland.toString().equals(region)) { s3Region = Region.EU_Ireland; } else { s3Region = Region.fromValue(region); } } if (!s3service.doesBucketExist(bucket)) { s3service.createBucket(bucket, s3Region); LOG.info("Created bucket [{}] in [{}] ", bucket, region); } else { LOG.info("Using bucket [{}] in [{}] ", bucket, region); } int writeThreads = 10; String writeThreadsStr = prop.getProperty(S3Constants.S3_WRITE_THREADS); if (writeThreadsStr != null) { writeThreads = Integer.parseInt(writeThreadsStr); } LOG.info("Using thread pool of [{}] threads in S3 transfer manager.", writeThreads); tmx = new TransferManager(s3service, (ThreadPoolExecutor) Executors.newFixedThreadPool(writeThreads, new NamedThreadFactory("s3-transfer-manager-worker"))); int asyncWritePoolSize = 10; String maxConnsStr = prop.getProperty(S3Constants.S3_MAX_CONNS); if (maxConnsStr != null) { asyncWritePoolSize = Integer.parseInt(maxConnsStr) - writeThreads; } asyncWriteExecuter = (ThreadPoolExecutor) Executors.newFixedThreadPool(asyncWritePoolSize, new NamedThreadFactory("s3-write-worker")); String renameKeyProp = prop.getProperty(S3Constants.S3_RENAME_KEYS); boolean renameKeyBool = (renameKeyProp == null || "".equals(renameKeyProp)) ? false : Boolean.parseBoolean(renameKeyProp); LOG.info("Rename keys [{}]", renameKeyBool); if (renameKeyBool) { renameKeys(); } LOG.debug("S3 Backend initialized in [{}] ms", +(System.currentTimeMillis() - startTime.getTime())); } catch (Exception e) { LOG.debug(" error ", e); Map<String, String> filteredMap = Maps.newHashMap(); if (prop != null) { filteredMap = Maps.filterKeys(Maps.fromProperties(prop), new Predicate<String>() { @Override public boolean apply(String input) { return !input.equals(S3Constants.ACCESS_KEY) && !input.equals(S3Constants.SECRET_KEY); } }); } throw new DataStoreException("Could not initialize S3 from " + filteredMap, e); } finally { if (contextClassLoader != null) { Thread.currentThread().setContextClassLoader(contextClassLoader); } } }
From source file:eu.eidas.auth.engine.core.DefaultCoreProperties.java
/** * Instantiates a new sAML core./*from ww w . j av a 2s . c o m*/ * * @param instance the instance */ public DefaultCoreProperties(@Nonnull Properties instance) { Preconditions.checkNotNull(instance, "instance"); samlCoreProp = Maps.fromProperties(instance); state = loadConfiguration(); }