Example usage for java.util Properties keySet

List of usage examples for java.util Properties keySet

Introduction

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

Prototype

@Override
    public Set<Object> keySet() 

Source Link

Usage

From source file:com.attilax.zip.FileUtil.java

@SuppressWarnings("unchecked")
public static final Map<String, String> getPropertiesMap(Class clazz, String fileName) throws Exception {
    Properties properties = new Properties();
    InputStream inputStream = clazz.getResourceAsStream(fileName);
    if (inputStream == null)
        inputStream = clazz.getClassLoader().getResourceAsStream(fileName);
    properties.load(inputStream);//from w  w w  . jav a  2  s .  com
    Map<String, String> map = new HashMap<String, String>();
    Set<Object> keySet = properties.keySet();
    for (Object key : keySet) {
        map.put((String) key, properties.getProperty((String) key));
    }
    return map;
}

From source file:jstorm.starter.util.Utility.java

/**
 * @param conf/*from   w w  w. java  2  s  .com*/
 * @param confFilePath
 * @return
 * @throws IOException
 */
private static boolean loadConfigHdfs(Configuration conf, String confFilePath) throws IOException {
    boolean found = false;

    FileSystem dfs = FileSystem.get(conf);
    Path src = new Path(confFilePath);
    FSDataInputStream fis = dfs.open(src);
    Properties configProps = new Properties();
    configProps.load(fis);

    for (Object key : configProps.keySet()) {
        String keySt = key.toString();
        conf.set(keySt, configProps.getProperty(keySt));
    }
    found = true;
    return found;
}

From source file:jstorm.starter.util.Utility.java

/**
 * @param conf//from   ww w  . jav a2 s  . c o m
 * @throws Exception
 */
public static void setConfiguration(Configuration conf) throws Exception {
    String confFilePath = conf.get("conf.path");
    if (null != confFilePath) {
        FileInputStream fis = new FileInputStream(confFilePath);
        Properties configProps = new Properties();
        configProps.load(fis);

        for (Object key : configProps.keySet()) {
            String keySt = key.toString();
            conf.set(keySt, configProps.getProperty(keySt));
        }
    }
}

From source file:jstorm.starter.util.Utility.java

/**
 * @param conf//  w w  w  . j a va  2  s . co  m
 * @param confFilePath
 * @param handleErr
 * @return
 * @throws IOException
 */
private static boolean loadConfig(Configuration conf, String confFilePath, boolean handleErr)
        throws IOException {
    boolean found = false;
    try {
        FileInputStream fis = new FileInputStream(confFilePath);
        Properties configProps = new Properties();
        configProps.load(fis);

        for (Object key : configProps.keySet()) {
            String keySt = key.toString();
            conf.set(keySt, configProps.getProperty(keySt));
        }
        found = true;
    } catch (FileNotFoundException ex) {
        if (!handleErr) {
            throw ex;
        }
    }
    return found;
}

From source file:com.aliyun.odps.ship.common.OptionsBuilder.java

private static void loadConfig() throws IOException, ODPSConsoleException {

    String cf = DshipContext.INSTANCE.getExecutionContext().getConfigFile();

    if (cf == null) {
        return;/*from  w ww . j a va 2s  . c  o  m*/
    }

    File file = new File(cf);
    if (!file.exists()) {
        return;
    }

    FileInputStream cfIns = new FileInputStream(file);
    Properties properties = new Properties();
    properties.load(cfIns);
    for (Object key : properties.keySet()) {
        String k = key.toString();
        String v = (String) properties.get(key);
        setContextValue(k.toLowerCase(), v);
    }
    cfIns.close();
}

From source file:com.joseflavio.iperoxo.IpeRoxo.java

/**
 * Configura a aplicao conforme os argumentos passados por linha de comando.
 *//*from w ww.ja  va  2  s  .c o m*/
private static void executarConfiguracao(String[] args) throws IOException {

    // Configuracao.Padrao.properties

    InputStream conf = IpeRoxo.class.getResourceAsStream("/Configuracao.Padrao.properties");
    try (Reader texto = new InputStreamReader(conf, "UTF-8")) {
        configuracao.load(texto);
    }

    // Configuracao.properties

    if (args.length >= 1) {

        File arquivo = new File(args[0]);
        log.info(getMensagem(null, "Log.Carregando.Configuracao") + ": " + arquivo.getAbsolutePath());

        if (!arquivo.exists()) {
            try (InputStream is = IpeRoxo.class.getResourceAsStream("/Configuracao.properties");
                    OutputStream os = new FileOutputStream(arquivo);) {
                IOUtils.copy(is, os);
            }
        }

        conf = new FileInputStream(arquivo);

    } else {

        log.info(getMensagem(null, "Log.Carregando.Configuracao.Padrao"));
        conf = IpeRoxo.class.getResourceAsStream("/Configuracao.properties");

    }

    try (Reader texto = new InputStreamReader(conf, "UTF-8")) {
        configuracao.load(texto);
    }

    // Codigos.properties

    conf = IpeRoxo.class.getResourceAsStream("/Codigos.properties");
    if (conf != null) {
        Properties props = new Properties();
        try (Reader texto = new InputStreamReader(conf, "UTF-8")) {
            props.load(texto);
        }
        for (Object chave : props.keySet()) {
            String nome = chave.toString();
            codigos.put(nome, Integer.parseInt(props.getProperty(nome)));
        }
    }

}

From source file:com.cloud.consoleproxy.ConsoleProxy.java

public static void startWithContext(Properties conf, Object context, byte[] ksBits, String ksPassword) {
    s_logger.info("Start console proxy with context");
    if (conf != null) {
        for (Object key : conf.keySet()) {
            s_logger.info("Context property " + (String) key + ": " + conf.getProperty((String) key));
        }//from   ww  w. j av  a 2 s  .  c o  m
    }

    configLog4j();
    Logger.setFactory(new ConsoleProxyLoggerFactory());

    // Using reflection to setup private/secure communication channel towards management server
    ConsoleProxy.context = context;
    ConsoleProxy.ksBits = ksBits;
    ConsoleProxy.ksPassword = ksPassword;
    try {
        Class<?> contextClazz = Class.forName("com.cloud.agent.resource.consoleproxy.ConsoleProxyResource");
        authMethod = contextClazz.getDeclaredMethod("authenticateConsoleAccess", String.class, String.class,
                String.class, String.class, String.class, Boolean.class);
        reportMethod = contextClazz.getDeclaredMethod("reportLoadInfo", String.class);
        ensureRouteMethod = contextClazz.getDeclaredMethod("ensureRoute", String.class);
    } catch (SecurityException e) {
        s_logger.error("Unable to setup private channel due to SecurityException", e);
    } catch (NoSuchMethodException e) {
        s_logger.error("Unable to setup private channel due to NoSuchMethodException", e);
    } catch (IllegalArgumentException e) {
        s_logger.error("Unable to setup private channel due to IllegalArgumentException", e);
    } catch (ClassNotFoundException e) {
        s_logger.error("Unable to setup private channel due to ClassNotFoundException", e);
    }

    // merge properties from conf file
    InputStream confs = ConsoleProxy.class.getResourceAsStream("/conf/consoleproxy.properties");
    Properties props = new Properties();
    if (confs == null) {
        s_logger.info("Can't load consoleproxy.properties from classpath, will use default configuration");
    } else {
        try {
            props.load(confs);

            for (Object key : props.keySet()) {
                // give properties passed via context high priority, treat properties from consoleproxy.properties
                // as default values
                if (conf.get(key) == null)
                    conf.put(key, props.get(key));
            }
        } catch (Exception e) {
            s_logger.error(e.toString(), e);
        }
    }

    start(conf);
}

From source file:com.flozano.socialauth.AuthProviderFactory.java

private static AuthProvider getProvider(final String id, final String fileName, final ClassLoader classLoader)
        throws Exception {
    Properties props = new Properties();
    AuthProvider provider;//  ww w .  java 2 s  . c  o m
    ClassLoader loader = null;
    if (classLoader != null) {
        loader = classLoader;
    } else {
        loader = AuthProviderFactory.class.getClassLoader();
    }
    try {
        InputStream in = loader.getResourceAsStream(fileName);
        props.load(in);
        for (Object key : props.keySet()) {
            String str = key.toString();
            if (str.startsWith("socialauth.")) {
                String val = str.substring("socialauth.".length());
                registerProvider(val, Class.forName(props.get(str).toString()));
            }
        }
    } catch (NullPointerException ne) {
        throw new FileNotFoundException(fileName + " file is not found in your class path");
    } catch (IOException ie) {
        throw new IOException("Could not load configuration from " + fileName);
    }

    provider = loadProvider(id, props);
    return provider;
}

From source file:net.ymate.platform.core.support.ConfigBuilder.java

public static ConfigBuilder create(final Properties properties) {
    ///*  ww  w  .  j a v  a  2s  .  co  m*/
    IModuleCfgProcessor _processor = new IModuleCfgProcessor() {
        @Override
        public Map<String, String> getModuleCfg(String moduleName) {
            Map<String, String> _cfgsMap = new HashMap<String, String>();
            // ?????
            for (Object _key : properties.keySet()) {
                String _prefix = "ymp.configs." + moduleName + ".";
                if (StringUtils.startsWith((String) _key, _prefix)) {
                    String _cfgKey = StringUtils.substring((String) _key, _prefix.length());
                    String _cfgValue = properties.getProperty((String) _key);
                    _cfgsMap.put(_cfgKey, _cfgValue);
                }
            }
            return _cfgsMap;
        }
    };
    //
    ConfigBuilder _builder = ConfigBuilder.create(_processor)
            .developMode(new BlurObject(properties.getProperty("ymp.dev_mode")).toBooleanValue())
            .packageNames(__doParserArrayStr(properties, "ymp.autoscan_packages"))
            .excludedFiles(__doParserArrayStr(properties, "ymp.excluded_files"))
            .excludedModules(__doParserArrayStr(properties, "ymp.excluded_modules"))
            .locale(StringUtils.trimToNull(properties.getProperty("ymp.i18n_default_locale")))
            .i18nEventHandler(ClassUtils.impl(properties.getProperty("ymp.i18n_event_handler_class"),
                    II18NEventHandler.class, ConfigBuilder.class));
    // ?????
    String _prefix = "ymp.params.";
    for (Object _key : properties.keySet()) {
        if (StringUtils.startsWith((String) _key, _prefix)) {
            String _cfgKey = StringUtils.substring((String) _key, _prefix.length());
            String _cfgValue = properties.getProperty((String) _key);
            _builder.param(_cfgKey, _cfgValue);
        }
    }
    //
    _prefix = "ymp.event.";
    for (Object _key : properties.keySet()) {
        if (StringUtils.startsWith((String) _key, _prefix)) {
            String _cfgKey = StringUtils.substring((String) _key, _prefix.length());
            String _cfgValue = properties.getProperty((String) _key);
            _builder.__eventConfigs.put(_cfgKey, _cfgValue);
        }
    }
    //
    return _builder;
}

From source file:com.mvdb.etl.actions.InitDB.java

private static void createConfiguration(ApplicationContext context) {
    final ConfigurationDAO configurationDAO = (ConfigurationDAO) context.getBean("configurationDAO");
    Properties topProps = ActionUtils.getTopProperties();
    if (topProps == null) {
        throw new RuntimeException("Unable to find top properties.");
    }//from   w ww  .  j  a v  a2s  .com
    List<String> commandList = new ArrayList<String>();
    commandList.add("DROP TABLE IF EXISTS configuration;");
    commandList.add("CREATE TABLE  configuration (" + " customer varchar(128)  NOT NULL, "
            + " name varchar(128)  NOT NULL," + " value varchar(128)  NOT NULL, "
            + " category varchar(32)  NOT NULL, " + " note varchar(512)  NOT NULL, "
            + "UNIQUE (customer, name, value, category)); ");

    Iterator<?> keysIter = topProps.keySet().iterator();
    while (keysIter.hasNext()) {
        String key = (String) keysIter.next();
        String value = topProps.getProperty(key);
        commandList.add("INSERT INTO configuration (customer, name, value, category, note) VALUES  ('global', '"
                + key + "', '" + value + "', '', '');");
    }
    commandList.add("COMMIT;");

    String[] commands = commandList.toArray(new String[0]);

    configurationDAO.executeSQl(commands);

}