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:io.mycat.server.packet.util.CharsetUtil.java

/**
 * ? index_to_charset.properties ? collationIndex  charsetName
 * ??SELECT ID,CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.COLLATIONS order by id;
 * //from w  w w. j a  v  a  2s.c om
 * ?charset_to_default_index.properties?charsetNamecollationIndex
 * ??SELECT CHARACTER_SET_NAME,ID FROM INFORMATION_SCHEMA.COLLATIONS where Default='Yes';
 * 
 * ????
 * 
 * ?? ? mysql???
 */
public static void getCharsetInfoFromFile() {
    Properties pros = new Properties();
    try {
        pros.load(CharsetUtil.class.getClassLoader().getResourceAsStream("index_to_charset.properties"));
        Iterator<Entry<Object, Object>> it = pros.entrySet().iterator();
        while (it.hasNext()) {
            Entry<Object, Object> entry = it.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            INDEX_TO_CHARSET.put(Integer.parseInt(key.toString()), value.toString());
        }
        //            System.out.println(JSON.toJSONString(INDEX_TO_CHARSET));

        pros.clear();
        pros.load(
                CharsetUtil.class.getClassLoader().getResourceAsStream("charset_to_default_index.properties"));
        it = pros.entrySet().iterator();
        while (it.hasNext()) {
            Entry<Object, Object> entry = it.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            CHARSET_TO_INDEX.put(key.toString(), Integer.parseInt(value.toString()));
        }
        //            System.out.println(JSON.toJSONString(CHARSET_TO_INDEX));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:ezbake.data.postgres.hibernate.HibernateUtil.java

private static SessionFactory buildSessionFactory(Properties ezConfig, EzSecurityToken token,
        SessionType sessionType) {//  www .jav a  2s. c  om
    try {
        String appName = ezConfig.getProperty(EzBakePropertyConstants.EZBAKE_APPLICATION_NAME);
        switch (sessionType) {
        case EZBAKE: {

            // Create the SessionFactory from hibernate.cfg.xml
            Configuration configuration = new Configuration();
            for (Map.Entry<Object, Object> entry : ezConfig.entrySet()) {
                String key = (String) entry.getKey();
                String value = (String) entry.getValue();

                configuration.setProperty("hibernate.connection." + key, value);
            }

            return configuration
                    .setProperty("hibernate.connection.driver_class", "ezbake.data.postgres.EzPostgresDriver")
                    .setProperty("hibernate.connection.username",
                            ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_USERNAME))
                    .setProperty("hibernate.connection.password",
                            ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_PASSWORD))
                    .setProperty("hibernate.connection.url",
                            String.format("jdbc:ezbake:postgresql://%s:%s/%s",
                                    ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_HOST),
                                    ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_PORT), appName))
                    .setProperty("hibernate.default_schema", "public")
                    .setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect")
                    .setProperty("EzSecurityToken",
                            new String(Base64.encodeBase64(new TSerializer().serialize(token)),
                                    Charsets.US_ASCII))
                    .setProperty("hibernate.hbm2ddl.auto", "update").configure().buildSessionFactory();
        }
        case POSTGRES: {
            return new Configuration().setProperty("hibernate.connection.driver_class", "org.postgresql.Driver")
                    .setProperty("hibernate.connection.username",
                            ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_USERNAME))
                    .setProperty("hibernate.connection.password",
                            ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_PASSWORD))
                    .setProperty("hibernate.connection.url",
                            String.format("jdbc:postgresql://%s:%s/%s",
                                    ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_HOST),
                                    ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_PORT), appName))
                    .setProperty("hibernate.default_schema", "public")
                    .setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect")
                    .setProperty("hibernate.show_sql", "true").setProperty("hibernate.hbm2ddl.auto", "update")
                    .configure().buildSessionFactory();
        }
        default: {
            throw new Exception("Invalid session type [" + sessionType + "].");
        }
        }
    } catch (Throwable ex) {
        // Make sure you log the exception, as it might be swallowed
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}

From source file:com.jkoolcloud.tnt4j.streams.inputs.KafkaStream.java

/**
 * Loads Kafka server configuration properties.
 *
 * @param userDefinedProps//ww w.j a v  a 2 s.c o m
 *            properties set to append
 * @return properties set appended with loaded Kafka server configuration properties
 *
 * @throws IOException
 *             if an error occurred when reading properties file
 */
protected static Properties getServerProperties(Properties userDefinedProps) throws IOException {
    putIfAbsent(userDefinedProps, "zookeeper.connect", "localhost:2181/tnt4j_kafka"); // NON-NLS

    Properties fProps = Utils.loadPropertiesFor(KS_PROP_FILE_KEY);

    for (Map.Entry<?, ?> pe : fProps.entrySet()) {
        putIfAbsent(userDefinedProps, String.valueOf(pe.getKey()), pe.getValue());
    }

    return userDefinedProps;
}

From source file:org.apache.hive.hcatalog.templeton.tool.TempletonUtils.java

public static StringBuilder dumpPropMap(String header, Properties props) {
    Map<String, String> map = new HashMap<String, String>();
    for (Map.Entry<Object, Object> ent : props.entrySet()) {
        map.put(ent.getKey().toString(), ent.getValue() == null ? null : ent.getValue().toString());
    }// www .jav a 2  s. c  o m
    return dumpPropMap(header, map);
}

From source file:com.savy3.util.DBConfiguration.java

/**
 * Converts connection properties to a String to be passed to the mappers.
 * @param properties JDBC connection parameters
 * @return String to be passed to configuration
 *//*from  ww w .ja va 2  s  .  c o  m*/
protected static String propertiesToString(Properties properties) {
    List<String> propertiesList = new ArrayList<String>(properties.size());
    for (Entry<Object, Object> property : properties.entrySet()) {
        String key = StringEscapeUtils.escapeCsv(property.getKey().toString());
        if (key.equals(property.getKey().toString()) && key.contains("=")) {
            key = "\"" + key + "\"";
        }
        String val = StringEscapeUtils.escapeCsv(property.getValue().toString());
        if (val.equals(property.getValue().toString()) && val.contains("=")) {
            val = "\"" + val + "\"";
        }
        propertiesList.add(StringEscapeUtils.escapeCsv(key + "=" + val));
    }
    return StringUtils.join(propertiesList, ',');
}

From source file:com.github.sparkfy.util.Log4jPropertyHelper.java

public static void updateLog4jConfiguration(/*Class<?> targetClass,*/
        String log4jPath) throws Exception {
    Properties customProperties = new Properties();
    FileInputStream fs = null;/*from ww w  .j  av  a 2s. c  o m*/
    InputStream is = null;
    try {
        fs = new FileInputStream(log4jPath);
        //      is = targetClass.getResourceAsStream("/log4j.properties");
        is = Utils.getClassLoader().getResourceAsStream("com/github/sparkfy/log4j-defaults.properties");
        customProperties.load(fs);
        Properties originalProperties = new Properties();
        originalProperties.load(is);
        for (Entry<Object, Object> entry : customProperties.entrySet()) {
            originalProperties.setProperty(entry.getKey().toString(), entry.getValue().toString());
        }
        LogManager.resetConfiguration();
        PropertyConfigurator.configure(originalProperties);
    } finally {
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(fs);
    }
}

From source file:gov.nih.nci.integration.util.CommonsPropertyLoaderUtil.java

/**
 * Load properties from following locations in mentioned order
 * /*  w ww  .j ava2  s.  co m*/
 * <pre>
 * #a)${user.home}/.integration/${ant.project.name}/${ant.project.name}.properties where ${user.home) is system property
 * #b)${app.home}/.integration/${ant.project.name} (where ${catalina.home) is a system property)
 * #c)classpath:${ant.project.name}.properties
 * </pre>
 * 
 * @param projectName - project name
 * @param propertyFileName - property file name
 * @return properties if it can resolve any of the property file, exceptions if no property file is available
 */
public static Properties loadProperties(final String projectName, final String propertyFileName) {
    if (StringUtils.isEmpty(projectName) || StringUtils.isEmpty(propertyFileName)) {
        throw new IllegalArgumentException("Project name and property file name must not be null!");
    }

    final String userHomePathToScan = String.format("user.home/.integration/%s/%s", projectName,
            propertyFileName);
    final String appHomePathToScan = String.format("app.home/.integration/%s/%s", projectName,
            propertyFileName);

    final Properties properties = new Properties();

    // 1. first load property from classpath
    fillProperties(new ClassPathResource(propertyFileName), properties);

    // 2. now merge properties from tomcat
    fillPropertiesFromFileSystem(properties, APP_HOME, appHomePathToScan);

    // 3. finally merge properties from user.home
    fillPropertiesFromFileSystem(properties, USER_HOME, userHomePathToScan);

    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        LOG.debug(String.format("loaded property - %s:%s", entry.getKey(), entry.getValue()));
    }
    return properties;

}

From source file:gov.nih.nci.cacis.common.util.CommonsPropertyLoaderUtil.java

/**
 * Load properties  from  following locations in mentioned order
 * <pre>/*  w w  w.ja va  2 s. com*/
 * #a)${user.home}/.cacis/${ant.project.name}/${ant.project.name}.properties  (where ${user.home) is a system property)
 * #b)${catalina.home}/conf/cacis/${ant.project.name} (where ${catalina.home) is a system property)
 * #c)classpath:${ant.project.name}.properties
 * </pre>
 *
 * @param projectName      - project name
 * @param propertyFileName - property file name
 * @return properties if it can resolve any of the property file, exceptions if no property file is available
 */
public static Properties loadProperties(final String projectName, final String propertyFileName) {
    Preconditions.checkNotNull(projectName, "Project name must not be null");
    Preconditions.checkNotNull(propertyFileName, "property file name must not be null");

    final String userHomePathToScan = String.format("user.home/.cacis/%s/%s", projectName, propertyFileName);
    final String tomcatHomePathToScan = String.format("catalina.home/conf/cacis/%s/%s", projectName,
            propertyFileName);

    final Properties properties = new Properties();

    //1. first load property from classpath
    fillProperties(new ClassPathResource(propertyFileName), properties);

    //2. now merge properties from tomcat
    fillPropertiesFromFileSystem(properties, TOMCAT_HOME, tomcatHomePathToScan);

    //3. finally merge properties from user.home
    fillPropertiesFromFileSystem(properties, USER_HOME, userHomePathToScan);

    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        LOG.info(String.format("loaded property - %s:%s", entry.getKey(), entry.getValue()));
    }
    return properties;

}

From source file:com.eviware.loadui.launcher.LoadUILauncher.java

private static void loadPropertiesFile() {
    Properties systemProperties = new Properties();
    try (FileInputStream fis = new FileInputStream("conf" + File.separator + "system.properties")) {
        systemProperties.load(fis);/*  w  w  w . j  a  v a  2s . c  o  m*/
        for (Entry<Object, Object> entry : systemProperties.entrySet())
            System.setProperty((String) entry.getKey(), (String) entry.getValue());
    } catch (IOException e) {
        // Ignore
    }
}

From source file:io.werval.cli.DamnSmallDevShell.java

private static void applySystemProperties(boolean debug, CommandLine cmd) {
    Properties systemProperties = cmd.getOptionProperties("D");
    for (Iterator<Map.Entry<Object, Object>> it = systemProperties.entrySet().iterator(); it.hasNext();) {
        Map.Entry<?, ?> entry = it.next();
        System.setProperty(entry.getKey().toString(), entry.getValue().toString());
    }/*w  w w  .  j a  v a  2s .  co m*/
    if (debug) {
        System.out.println("Applied System Properties are: " + systemProperties);
    }
}