List of usage examples for java.util Properties containsKey
@Override public boolean containsKey(Object key)
From source file:org.springframework.xd.distributed.util.ServerProcessUtils.java
/** * Start an instance of the admin server. This method will block until * the admin server is capable of processing HTTP requests. Upon test * completion, the method {@link com.oracle.tools.runtime.java.JavaApplication#close()} * should be invoked to shut down the server. * * @param properties system properties to pass to the container; at minimum * must contain key {@code zk.client.connect} to indicate * the ZooKeeper connect string and key {@code server.port} * to indicate the admin server port * * @return admin server application reference * @throws IOException if an exception is thrown launching the process * @throws InterruptedException if the executing thread is interrupted *//* ww w .j a v a 2s. c o m*/ public static JavaApplication<SimpleJavaApplication> startAdmin(Properties properties) throws IOException, InterruptedException { Assert.state(properties.containsKey("zk.client.connect"), "Property 'zk.client.connect' required"); Assert.state(properties.containsKey("server.port"), "Property 'server.port' required"); JavaApplication<SimpleJavaApplication> adminServer = launch(AdminServerApplication.class, false, properties, null); logger.debug("waiting for admin server"); waitForAdminServer("http://localhost:" + properties.getProperty("server.port")); logger.debug("admin server ready"); return adminServer; }
From source file:com.limegroup.gnutella.util.FrostWireUtils.java
public static Set<File> getFrostWire4SaveDirectories() { Set<File> result = new HashSet<File>(); try {/*from w w w. j a va 2 s . c om*/ File settingFile = new File(CommonUtils.getFrostWire4UserSettingsDir(), "frostwire.props"); Properties props = new Properties(); FileInputStream fis = new FileInputStream(settingFile); props.load(fis); IOUtils.closeQuietly(fis); if (props.containsKey("DIRECTORY_FOR_SAVING_FILES")) { result.add(new File(props.getProperty("DIRECTORY_FOR_SAVING_FILES"))); } String[] types = new String[] { "document", "application", "audio", "video", "image" }; for (String type : types) { String key = "DIRECTORY_FOR_SAVING_" + type + "_FILES"; if (props.containsKey(key)) { result.add(new File(props.getProperty(key))); } } } catch (Exception e) { // ignore } return result; }
From source file:com.izforge.izpack.util.LogUtils.java
private static void mergeLoggingConfiguration(Properties to, Properties from) { for (String fromName : from.stringPropertyNames()) { String fromValue = from.getProperty(fromName); if (fromName.matches("\\.?handlers") && to.containsKey(fromName)) { String oldValue = to.getProperty(fromName); if (!fromValue.equals(oldValue)) { to.setProperty(fromName, oldValue + ", " + fromValue); }// w w w. j av a2 s . c o m continue; } if (!to.containsKey(fromName)) { to.setProperty(fromName, fromValue); } } }
From source file:gov.lanl.util.DBCPUtils.java
/** * Set-up a DBCP DataSource from a properties object. Uses a properties * key prefix to identify the properties associated with profile. If * a database profile has a prefix of djatoka, the props object would * contain the following pairs://from ww w .java 2 s .co m * djatoka.url=jdbc:mysql://localhost/djatoka * djatoka.driver=com.mysql.jdbc.Driver * djatoka.login=root * djatoka.pwd= * djatoka.maxActive=50 * djatoka.maxIdle=10 * @param dbid database profile properties file prefix * @param props properties object containing relevant pairs */ public static DataSource setupDataSource(String dbid, Properties props) throws Exception { String url = props.getProperty(dbid + ".url"); String driver = props.getProperty(dbid + ".driver"); String login = props.getProperty(dbid + ".login"); String pwd = props.getProperty(dbid + ".pwd"); int maxActive = 50; if (props.containsKey(dbid + ".maxActive")) maxActive = Integer.parseInt(props.getProperty(dbid + ".maxActive")); int maxIdle = 10; if (props.containsKey(dbid + ".maxIdle")) maxIdle = Integer.parseInt(props.getProperty(dbid + ".maxIdle")); log.debug(url + ";" + driver + ";" + login + ";" + pwd + ";" + maxActive + ";" + maxIdle); return setupDataSource(url, driver, login, pwd, maxActive, maxIdle); }
From source file:io.orchestrate.client.ClientFilter.java
private static String buildBaseUserAgent() { String version = "unknown"; try {//from ww w .j a v a 2s.co m final Properties props = new Properties(); String basePath = "/" + ClientFilter.class.getPackage().getName().replace('.', '/'); props.load(ClientFilter.class.getResourceAsStream(basePath + "/build.properties")); if (props.containsKey("version")) { version = props.getProperty("version"); } } catch (final Exception ignored) { } return String.format("OrchestrateJavaClient/%s (Java/%s; %s)", version, System.getProperty("java.version"), System.getProperty("java.vendor")); }
From source file:com.adaptris.core.management.jetty.ServerBuilder.java
private static Server configure(final Server server, final Properties config) throws Exception { // TODO This is all wrong. Can't get server attributes from the SErvletContext // OLD-SKOOL Do it via SystemProperties!!!!! // Add Null Prodction in to avoid System.setProperty issues during tests. // Or in fact if people decide to not enable JMXServiceUrl in bootstrap.properties if (config.containsKey(Constants.CFG_JMX_LOCAL_ADAPTER_UID)) { // server.setAttribute(ATTR_JMX_ADAPTER_UID, config.getProperty(Constants.CFG_JMX_LOCAL_ADAPTER_UID)); System.setProperty(ATTR_JMX_ADAPTER_UID, config.getProperty(Constants.CFG_JMX_LOCAL_ADAPTER_UID)); }//from w w w.j a v a 2s . c om if (config.containsKey(Constants.BOOTSTRAP_PROPERTIES_RESOURCE_KEY)) { for (String s : ATTR_BOOTSTRAP_KEYS) { System.setProperty(s, config.getProperty(Constants.BOOTSTRAP_PROPERTIES_RESOURCE_KEY)); } } return server; }
From source file:com.att.api.oauth.OAuthToken.java
/** * Attempts to load an OAuthToken from a file in an asynchronous-safe * manner.//from ww w . jav a2s. c om * * <p> * If <code>fpath</code> does not exist or some required values are missing * from the saved file, null is returned. * </p> * * <p> * <strong>WARNING</strong>: Because caching may be used, manually modifying * the saved token properties file may yield unexpected results unless * caching is disabled. * </p> * * @param fpath file path from which to load token * @return OAuthToken an OAuthToken object if successful, null otherwise * @throws IOException if there was an error loading the token * @see #useTokenCaching(boolean) */ public static OAuthToken loadToken(String fpath) throws IOException { FileInputStream fInputStream = null; FileLock fLock = null; synchronized (LOCK_OBJECT) { // attempt to load from cached tokens, thereby saving file I/O if (cachedTokens != null && cachedTokens.get(fpath) != null) { return cachedTokens.get(fpath); } if (!new File(fpath).exists()) { return null; } try { fInputStream = new FileInputStream(fpath); // acquire shared lock fLock = fInputStream.getChannel().lock(0L, Long.MAX_VALUE, true); Properties props = new Properties(); props.load(fInputStream); if (!props.containsKey("creationTime") || !props.containsKey("expiresIn")) { return null; } String accessToken = props.getProperty("accessToken"); if (accessToken == null || accessToken.equals("")) { return null; } String refreshToken = props.getProperty("refreshToken"); String sExpiresIn = props.getProperty("expiresIn"); long expiresIn = new Long(sExpiresIn).longValue(); String sCreationTime = props.getProperty("creationTime"); long creationTime = new Long(sCreationTime).longValue(); return new OAuthToken(accessToken, expiresIn, refreshToken, creationTime); } catch (IOException e) { throw e; // pass along exception } finally { if (fLock != null) { fLock.release(); } if (fInputStream != null) { fInputStream.close(); } } } }
From source file:com.haulmont.cuba.core.entity.LocaleHelper.java
public static String getLocalizedName(String localeBundle) { Locale locale = AppBeans.get(UserSessionSource.class).getLocale(); String localeName = null;//from w w w . j av a2s.c o m if (StringUtils.isNotEmpty(localeBundle)) { Properties localeProperties = loadProperties(localeBundle); if (localeProperties != null) { String key = locale.getLanguage(); if (StringUtils.isNotEmpty(locale.getCountry())) key += "_" + locale.getCountry(); if (localeProperties.containsKey(key)) localeName = (String) localeProperties.get(key); } } return localeName; }
From source file:net.certifi.audittablegen.AuditTableGen.java
static DataSource getRunTimeDataSource(Properties props) { DataSource ds;/*w ww .java 2s . c o m*/ String driver; if (props.containsKey("url")) { driver = props.getProperty("driver", ""); if (driver.toLowerCase().contains("hsqldb")) { ds = HsqldbDMR.getRunTimeDataSource(props); } else if (driver.toLowerCase().contains("postgresql")) { ds = PostgresqlDMR.getRunTimeDataSource(props); } else { //take a shot at it with user supplied driver & url ds = GenericDMR.getRunTimeDataSource(props); } } else if (props.containsKey("driver")) { driver = props.getProperty("driver", ""); if (driver.toLowerCase().contains("hsqldb")) { ds = HsqldbDMR.getRunTimeDataSource(props); } else if (driver.toLowerCase().contains("postgresql")) { ds = PostgresqlDMR.getRunTimeDataSource(props); } else { //take a shot at it with user supplied driver & url ds = GenericDMR.getRunTimeDataSource(props); } } else { //no url provided //in memory hsqldb - testing only ds = HsqldbDMR.getRunTimeDataSource(); } return ds; }
From source file:com.heliosapm.streams.collector.ds.pool.PoolConfig.java
/** * Creates and deploys an ObjectPool based on the passed config props * @param configProps The configuration properties file * @return the created GenericObjectPool *//* w w w . j av a 2 s . c o m*/ public static GenericObjectPool<?> deployPool(final File configProps) { if (configProps == null) throw new IllegalArgumentException("The passed file was null"); if (!configProps.canRead()) throw new IllegalArgumentException("The passed file [" + configProps + "] cannot be read"); GenericObjectPool<?> pool = pools.putIfAbsent(configProps, PLACEHOLDER); if (pool == null || pool == PLACEHOLDER) { final Properties p = URLHelper.readProperties(URLHelper.toURL(configProps)); if (!p.containsKey("name")) { p.setProperty("name", StringHelper.splitString(configProps.getName(), '.', true)[0]); } try { pool = deployPool(p); pools.replace(configProps, pool); return pool; } catch (Exception ex) { final String msg = "Failed to deploy object pool from file [" + configProps + "]"; LOG.error(msg, ex); throw new RuntimeException(msg, ex); } } else { throw new RuntimeException( "The pool defined in the file [" + configProps + "] has already been deployed"); } }