Example usage for java.util Properties remove

List of usage examples for java.util Properties remove

Introduction

In this page you can find the example usage for java.util Properties remove.

Prototype

@Override
    public synchronized Object remove(Object key) 

Source Link

Usage

From source file:org.apache.openejb.resource.jdbc.dbcp.DbcpDataSourceCreator.java

@Override
public CommonDataSource pool(final String name, final String driver, final Properties properties) {
    final String xa = String.class.cast(properties.remove("XaDataSource"));
    if (xa != null) {
        return XADataSourceResource.proxy(Thread.currentThread().getContextClassLoader(), xa);
    }/*  ww w  .ja va2  s  . c om*/

    if (!properties.containsKey("JdbcDriver")) {
        properties.setProperty("driverClassName", driver);
    }
    properties.setProperty("name", name);

    final BasicDataSource ds = build(BasicDataSource.class, properties);
    ds.setDriverClassName(driver);
    // if (xa != null) ds.setDelegate(XADataSourceResource.proxy(Thread.currentThread().getContextClassLoader(), xa));

    return ds;
}

From source file:org.commonjava.maven.galley.cache.infinispan.FastLocalCacheProviderBaseTest.java

@Test(expected = java.lang.IllegalArgumentException.class)
public void testConstructorWitNoNFSSysPath() throws IOException {
    Properties props = System.getProperties();
    props.remove(FastLocalCacheProvider.NFS_BASE_DIR_KEY);
    System.setProperties(props);//from  ww w. j  a  va 2s.co  m
    final String NON_EXISTS_PATH = "";
    new FastLocalCacheProvider(new PartyLineCacheProvider(temp.newFolder(), pathgen, events, decorator),
            new SimpleCacheInstance<>("test", nfsOwnerCache), pathgen, events, decorator, executor,
            NON_EXISTS_PATH, new SimpleCacheInstance<>("localFileCache", localFileCache));
}

From source file:org.elasticsearch.hadoop.hive.HiveEmbeddedServer.java

private HiveConf configure() throws Exception {
    FileUtils.deleteQuietly(new File("/tmp/hive"));

    HiveConf conf = new HiveConf();
    // work-around for NTFS FS
    if (TestUtils.isWindows()) {
        conf.set("fs.file.impl", NTFSLocalFileSystem.class.getName());
        //conf.set("hadoop.bin.path", getClass().getClassLoader().getResource("hadoop.cmd").getPath());
        System.setProperty("path.separator", ";");
    }/* www  .j  av a  2 s  .c om*/
    conf.set("hive.metastore.warehouse.dir", "/tmp/hive/warehouse");
    conf.set("hive.metastore.metadb.dir", "/tmp/hive/metastore_db");
    conf.set("hive.exec.scratchdir", "/tmp/hive");
    conf.set("javax.jdo.option.ConnectionURL", "jdbc:derby:;databaseName=/tmp/hive/metastore_db;create=true");
    conf.set("hive.metastore.local", "true");
    conf.set("hive.aux.jars.path", "");
    conf.set("hive.added.jars.path", "");
    conf.set("hive.added.files.path", "");
    conf.set("hive.added.archives.path", "");

    // clear mapred.job.tracker - Hadoop defaults to 'local' if not defined. Hive however expects this to be set to 'local' - if it's not, it does a remote execution (i.e. no child JVM)
    Field field = Configuration.class.getDeclaredField("properties");
    field.setAccessible(true);
    Properties props = (Properties) field.get(conf);
    props.remove("mapred.job.tracker");

    // intercept SessionState to clean the threadlocal
    Field tss = SessionState.class.getDeclaredField("tss");
    tss.setAccessible(true);
    tss.set(null, new InterceptingThreadLocal());

    return conf;
}

From source file:de.tudarmstadt.ukp.csniper.webapp.support.uima.AnalysisEngineFactory.java

/**
 * Create an AnalysisEngine from a .properties file.
 * //from w  ww  .j  a  va2s . c o m
 * @param aSettingsFile
 *            filename of the file which specifies the options for the AE
 * @param aAdditionalParameters
 *            additional parameters for the AE
 * @return an AnalysisEngine with the specified parameters
 */
public static AnalysisEngine createAnalysisEngine(String aSettingsFile, Object... aAdditionalParameters)
        throws ResourceInitializationException {
    Properties options = new Properties();
    InputStream is = null;
    try {
        File settingsFile = new File(getSettingsPath(), aSettingsFile);
        // first look in the settings directory for the specified file
        if (settingsFile.exists()) {
            is = new FileInputStream(settingsFile);
            log.info("Loading AnalysisEngine from " + settingsFile.getAbsolutePath());
        }
        // if the file cannot be found, use the default file from the classpath
        else {
            is = ResourceUtils.resolveLocation("classpath:" + aSettingsFile).openStream();
            log.info("Loading AnalysisEngine from classpath:" + aSettingsFile);
        }
        options.load(is);
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    } finally {
        IOUtils.closeQuietly(is);
    }

    // find class
    String classname;
    try {
        classname = (String) options.remove("classname");
    } catch (NullPointerException e) {
        throw new IllegalArgumentException(
                "The properties file needs a property [classname] whose value has to be the qualified pathname of the analysis engine class that should be used.");
    }

    // check for additional parameters
    if (aAdditionalParameters.length % 2 == 1) {
        throw new IllegalArgumentException("Illegal number of additional parameters ["
                + aAdditionalParameters.length + "], has to be an even amount.");
    }

    // create list of parameters
    List<Object> params = new ArrayList<Object>();
    for (Entry<Object, Object> param : options.entrySet()) {
        params.add(param.getKey());
        params.add(convert(param.getValue()));
    }
    for (Object adParam : aAdditionalParameters) {
        params.add(convert(adParam));
    }

    // create class
    Class<? extends AnalysisComponent> aeClass;
    try {
        aeClass = Class.forName(classname).asSubclass(AnalysisComponent.class);
    } catch (ClassNotFoundException e) {
        throw new ResourceInitializationException(e);
    }

    log.info("Creating AnalysisEngine [" + classname + "] with following options: "
            + StringUtils.join(params, ","));

    return createPrimitive(aeClass, params.toArray());
}

From source file:org.apache.karaf.eik.core.KarafCorePluginUtils.java

/**
 * Loads a configuration file relative to the specified base directory. This
 * method also processes any include directives that import other properties
 * files relative to the specified property file.
 *
 * @param base//  w w  w  .jav  a  2  s  .c  o m
 *            the directory containing the file
 * @param filename
 *            the relative path to the properties file
 * @param processIncludes
 *            true if {@link #INCLUDES_PROPERTY} statements should be
 *            followed; false otherwise.
 * @return the {@link Properties} object created from the contents of
 *         configuration file
 * @throws CoreException
 *             if there is a problem loading the file
 */
public static Properties loadProperties(final File base, final String filename, final boolean processIncludes)
        throws CoreException {
    final File f = new File(base, filename);

    try {
        final Properties p = new Properties();
        p.load(new FileInputStream(f));

        if (processIncludes) {
            final String includes = p.getProperty(INCLUDES_PROPERTY);
            if (includes != null) {
                final StringTokenizer st = new StringTokenizer(includes, "\" ", true);
                if (st.countTokens() > 0) {
                    String location;
                    do {
                        location = nextLocation(st);
                        if (location != null) {
                            final Properties includeProps = loadProperties(base, location);
                            p.putAll(includeProps);
                        }
                    } while (location != null);
                }
                p.remove(INCLUDES_PROPERTY);
            }
        }

        return p;
    } catch (final IOException e) {
        final String message = "Unable to load configuration file from configuration directory: "
                + f.getAbsolutePath();
        throw new CoreException(
                new Status(IStatus.ERROR, KarafCorePluginActivator.PLUGIN_ID, IStatus.OK, message, e));
    }

}

From source file:org.ow2.parserve.PARServeEngine.java

/**
 * Creates all configuration data related to Rserve
 *
 * @return/*from w  w  w .jav a  2 s . c  om*/
 * @throws IOException
 */
private static RServeConf createConfig() throws IOException {
    long timeout = -1;
    boolean debug = false;
    boolean daemon = false;
    String login = null;
    String password = null;
    int rServePort = PARSERVE_RSERVE_PORT;
    Properties rServeProperties = null;
    Properties rEnvProperties = null;
    if (rServePropertyFile.exists()) {
        rServeProperties = new Properties();
        rServeProperties.load(new FileReader(rServePropertyFile));
        Set<String> propNames = rServeProperties.stringPropertyNames();
        // filter properties starting with "R." or special properties
        for (String key : propNames) {
            if (key.startsWith("R.")) {
                String newkey = key.substring(2);
                if (rEnvProperties == null) {
                    rEnvProperties = new Properties();
                }
                rEnvProperties.put(newkey, rServeProperties.remove(key));
            } else if (key.equals("rserve.daemon")) {
                daemon = Boolean.parseBoolean((String) rServeProperties.remove(key));
                rServeProperties.remove(key);
            } else if (key.equals("rserve.debug")) {
                debug = Boolean.parseBoolean((String) rServeProperties.remove(key));
                rServeProperties.remove(key);
            } else if (key.equals("port")) {
                rServePort = Integer.parseInt((String) rServeProperties.get("port"));
            } else if (key.equals("rserve.login")) {
                login = (String) rServeProperties.remove(key);
            } else if (key.equals("rserve.password")) {
                password = (String) rServeProperties.remove(key);
            } else if (key.equals("rserve.timeout")) {
                timeout = Long.parseLong((String) rServeProperties.remove(key));
            }
        }
    }
    return new RServeConf(null, rServePort, login, password, timeout, daemon, debug, rServeProperties,
            rEnvProperties);
}

From source file:org.openhab.binding.amazonechocontrol.internal.StateStorage.java

public void storeState(@Nullable String key, @Nullable String value) {
    synchronized (this) {
        if (key == null) {
            return;
        }/*w w w . j ava  2 s .  c o  m*/
        Properties properties = initProperties();
        if (StringUtils.isEmpty(value)) {
            properties.remove(key);
        } else {
            properties.setProperty(key, value);
        }
        // store the property also in OH to see it in the GUI
        thing.setProperty(key, value);
        saveProperties();
    }
}

From source file:org.bonitasoft.console.common.server.preferences.properties.ConfigurationFilesManager.java

public void removeProperty(String propertiesFilename, long tenantId, String propertyName) throws IOException {
    Map<String, Properties> resources = getResources(tenantId);
    Properties properties = resources.get(propertiesFilename);
    properties.remove(propertyName);
    update(tenantId, propertiesFilename, properties);
}

From source file:com.norconex.commons.lang.map.PropertiesTest.java

@Test
public void testRemove() throws Exception {
    Properties properties = new Properties();
    List<String> list = asList("a", "b", "c");
    properties.put("key", list);
    assertEquals(list, properties.remove("key"));
}

From source file:org.jajuk.util.UtilString.java

/**
 * Gets the anonymized system properties.
 *
 * @return Anonymized System properties (for log or quality agent)
 *//* w w  w.j a  va  2s .c o m*/
public static Properties getAnonymizedSystemProperties() {
    final Properties properties = (Properties) System.getProperties().clone();
    // We remove sensible data from logs
    /*
     * can contain external program paths
     */
    properties.remove("java.library.path");
    properties.remove("java.class.path");
    // user name is private
    properties.remove("user.name");
    properties.remove("java.ext.dirs");
    properties.remove("sun.boot.class.path");
    properties.remove("deployment.user.security.trusted.certs");
    properties.remove("deployment.user.security.trusted.clientauthcerts");
    properties.remove("jajuk.log");
    return properties;
}