Example usage for java.util Properties entrySet

List of usage examples for java.util Properties entrySet

Introduction

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

Prototype

@Override
    public Set<Map.Entry<Object, Object>> entrySet() 

Source Link

Usage

From source file:interactivespaces.configuration.FileSystemConfigurationStorageManager.java

/**
 * Load the contents of a configuration file into a configuration.
 *
 * @param configuration// w  ww.  j a  va2s  .  c o  m
 *          the configuration to place values in
 * @param configFile
 *          the file to load into the configuration
 */
private void loadConfigFile(Configuration configuration, File configFile) {
    InputStream in = null;
    try {
        if (log.isInfoEnabled()) {
            log.info(String.format("Loading config file %s", configFile));
        }

        in = new FileInputStream(configFile);

        Properties configProperties = new Properties();
        configProperties.load(in);

        for (Entry<Object, Object> entry : configProperties.entrySet()) {
            configuration.setValue(entry.getKey().toString(), entry.getValue().toString());
        }
    } catch (Exception e) {
        log.error("Could not load configuration", e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (Exception e) {
                // Don't care.
            }
        }
    }
}

From source file:org.apache.hadoop.metrics.ContextFactory.java

private void setAttributes(Properties properties) {
    if (properties != null) {
        for (Map.Entry<Object, Object> keyValue : properties.entrySet()) {
            setAttribute((String) keyValue.getKey(), (String) keyValue.getValue());
        }/*from ww  w.j a v  a 2 s  . com*/
    }
}

From source file:org.carewebframework.api.alias.AliasTypeRegistry.java

/**
 * Load aliases from a property file.//  w  ww .jav  a 2  s. c  o m
 * 
 * @param applicationContext The application context.
 * @param propertyFile A property file.
 */
private void loadAliases(ApplicationContext applicationContext, String propertyFile) {
    if (propertyFile.isEmpty()) {
        return;
    }

    Resource[] resources;

    try {
        resources = applicationContext.getResources(propertyFile);
    } catch (IOException e) {
        log.error("Failed to locate alias property file: " + propertyFile, e);
        return;
    }

    for (Resource resource : resources) {
        if (!resource.exists()) {
            log.info("Did not find alias property file: " + resource.getFilename());
            continue;
        }

        InputStream is = null;

        try {
            is = resource.getInputStream();
            Properties props = new Properties();
            props.load(is);

            for (Entry<Object, Object> entry : props.entrySet()) {
                try {
                    register((String) entry.getKey(), (String) entry.getValue());
                    entryCount++;
                } catch (Exception e) {
                    log.error("Error registering alias for '" + entry.getKey() + "'.", e);
                }
            }

            fileCount++;
        } catch (IOException e) {
            log.error("Failed to load alias property file: " + resource.getFilename(), e);
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
}

From source file:com.cloudera.sqoop.ConnFactory.java

/**
 * Read the specified file and extract any ManagerFactory implementation
 * names from there.//from   w w  w. ja v  a  2 s .  co  m
 * @param conf the configuration to populate.
 * @param f the file containing the configuration data to add.
 */
private void addManagersFromFile(Configuration conf, File f) {
    Reader r = null;
    try {
        // The file format is actually Java properties-file syntax.
        r = new InputStreamReader(new FileInputStream(f));
        Properties props = new Properties();
        props.load(r);

        for (Map.Entry<Object, Object> entry : props.entrySet()) {
            // Each key is a ManagerFactory class name.
            // Each value, if set, is the jar that contains it.
            String factory = entry.getKey().toString();
            addManager(conf, factory);

            String jarName = entry.getValue().toString();
            if (jarName.length() > 0) {
                ClassLoaderStack.addJarFile(jarName, factory);
                LOG.debug("Added factory " + factory + " in jar " + jarName + " specified by " + f);
            } else if (LOG.isDebugEnabled()) {
                LOG.debug("Added factory " + factory + " specified by " + f);
            }
        }
    } catch (IOException ioe) {
        LOG.error("Error loading ManagerFactory information from file " + f + ": "
                + StringUtils.stringifyException(ioe));
    } finally {
        if (null != r) {
            try {
                r.close();
            } catch (IOException ioe) {
                LOG.warn("Error closing file " + f + ": " + ioe);
            }
        }
    }
}

From source file:halfpipe.properties.UrlPropertiesSource.java

private void loadConfig(Map<String, Object> map, URL url) throws IOException {
    Properties props = new Properties();
    InputStream fin = url.openStream();
    props.load(fin);//from w  ww .  j av  a2s .  com
    fin.close();
    for (Entry<Object, Object> entry : props.entrySet()) {
        map.put((String) entry.getKey(), entry.getValue());
    }
}

From source file:org.apache.archiva.redback.rbac.jdo.JdoRbacManagerTest.java

/**
 * Creates a new RbacStore which contains no data.
 *//*from  ww  w  .j  av a2  s  .  c  o  m*/
@Before
public void setUp() throws Exception {

    super.setUp();

    assertEquals(DefaultConfigurableJdoFactory.class.getName(), jdoFactory.getClass().getName());

    jdoFactory.setPersistenceManagerFactoryClass("org.jpox.PersistenceManagerFactoryImpl"); //$NON-NLS-1$

    jdoFactory.setDriverName(System.getProperty("jdo.test.driver", "org.hsqldb.jdbcDriver")); //$NON-NLS-1$  //$NON-NLS-2$

    jdoFactory.setUrl(System.getProperty("jdo.test.url", "jdbc:hsqldb:mem:" + getName())); //$NON-NLS-1$  //$NON-NLS-2$

    jdoFactory.setUserName(System.getProperty("jdo.test.user", "sa")); //$NON-NLS-1$

    jdoFactory.setPassword(System.getProperty("jdo.test.pass", "")); //$NON-NLS-1$

    jdoFactory.setProperty("org.jpox.transactionIsolation", "READ_COMMITTED"); //$NON-NLS-1$ //$NON-NLS-2$

    jdoFactory.setProperty("org.jpox.poid.transactionIsolation", "READ_COMMITTED"); //$NON-NLS-1$ //$NON-NLS-2$

    jdoFactory.setProperty("org.jpox.autoCreateSchema", "true"); //$NON-NLS-1$ //$NON-NLS-2$

    jdoFactory.setProperty("org.jpox.autoCreateTables", "true");

    jdoFactory.setProperty("javax.jdo.option.RetainValues", "true");

    jdoFactory.setProperty("javax.jdo.option.RestoreValues", "true");

    // jdoFactory.setProperty( "org.jpox.autoCreateColumns", "true" );

    jdoFactory.setProperty("org.jpox.validateTables", "true");

    jdoFactory.setProperty("org.jpox.validateColumns", "true");

    jdoFactory.setProperty("org.jpox.validateConstraints", "true");

    /* Enable the level 2 Ehcache class-based cache */
    jdoFactory.setProperty("org.jpox.cache.level2", "true");
    jdoFactory.setProperty("org.jpox.cache.level2.type", "ehcacheclassbased");
    jdoFactory.setProperty("org.jpox.cache.level2.configurationFile", "/ehcache.xml"); // ehcache config
    jdoFactory.setProperty("org.jpox.cache.level2.cacheName", "default"); // default cache name

    Properties properties = jdoFactory.getProperties();

    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        System.setProperty((String) entry.getKey(), (String) entry.getValue());
    }

    URL[] jdoFileUrls = new URL[] {
            getClass().getResource("/org/apache/archiva/redback/rbac/jdo/package.jdo") }; //$NON-NLS-1$

    if ((jdoFileUrls == null) || (jdoFileUrls[0] == null)) {
        fail("Unable to process test " + getName() + " - missing package.jdo.");
    }

    File propsFile = null; // intentional
    boolean verbose = true;

    PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory();

    assertNotNull(pmf);

    /* set our own Store Manager to allow counting SQL statements */
    StoreManagerDebug.setup((AbstractPersistenceManagerFactory) pmf);

    /* clean up the db */
    SchemaTool.deleteSchemaTables(jdoFileUrls, new URL[] {}, propsFile, verbose);
    SchemaTool.createSchemaTables(jdoFileUrls, new URL[] {}, propsFile, verbose, null);

    PersistenceManager pm = pmf.getPersistenceManager();

    pm.close();

    setRbacManager(rbacManager);

    /* save the store manager to access the queries executed */
    JdoRbacManager rbacManager = (JdoRbacManager) getRbacManager();
    storeManager = StoreManagerDebug.getConfiguredStoreManager(rbacManager.getJdo().getPersistenceManager());
}

From source file:org.eluder.coveralls.maven.plugin.json.JsonWriter.java

private void writeOptionalEnvironment(final String field, final Properties properties)
        throws ProcessingException, IOException {
    if (properties != null) {
        generator.writeObjectFieldStart(field);
        for (Entry<Object, Object> property : properties.entrySet()) {
            writeOptionalString(property.getKey().toString(), property.getValue().toString());
        }/*  ww  w .j a  v a  2 s .  co m*/
        generator.writeEndObject();
    }
}

From source file:com.wrmsr.neurosis.util.Configs.java

public static Map<String, String> loadByExtension(byte[] data, String extension) {
    if (extension == "properties") {
        Properties properties = new Properties();
        try {/*from   w  w w .  j a  v  a 2 s.c o m*/
            properties.load(new StringReader(new String(data)));
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
        return properties.entrySet().stream().filter(e -> e.getValue() != null).collect(
                ImmutableCollectors.toImmutableMap(e -> e.getKey().toString(), e -> e.getValue().toString()));
    } else if (Serialization.OBJECT_MAPPERS_BY_EXTENSION.containsKey(extension)) {
        ObjectMapper objectMapper = Serialization.OBJECT_MAPPERS_BY_EXTENSION.get(extension).get();
        Object value;
        try {
            value = objectMapper.readValue(data, Object.class);
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
        return flatten(value);
    } else {
        throw new IllegalArgumentException(String.format("Unhandled config extension: %s", extension));
    }
}

From source file:com.wyp.module.controller.LicenseController.java

/**
 * ?/*from   ww  w.j a v a2  s  . c  o m*/
 * 
 * @param properties
 */
private void initProperties(Properties properties) {
    Set<Entry<Object, Object>> set = properties.entrySet();
    if (null != set) {
        for (Entry<Object, Object> entry : set) {
            map.put(entry.getKey().toString(), entry.getValue().toString());
        }
    }
}