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:orca.util.db.MySqlBase.java

/**
 * Helper function to construct a query. Constructs a query of the form
 * key1='value1', key2='value2' etc from the Properties list it is passed
 * @param p Properties list/*from   www.  j a  v a2  s  . c o m*/
 * @return query string
 */
public static String constructQueryPartial(Properties p) {
    StringBuffer query = new StringBuffer("");
    Iterator<?> i = p.entrySet().iterator();

    while (i.hasNext()) {
        if (query.length() > 0) {
            query.append(", ");
        }

        Map.Entry<?, ?> entry = (Map.Entry<?, ?>) i.next();
        String name = (String) entry.getKey();
        String value = (String) entry.getValue();
        query.append(name + "='" + value + "'");
    }

    return query.toString();
}

From source file:de.egore911.versioning.deployer.performer.PerformReplacement.java

static void perform(File directory, List<String> wildcards, List<ReplacementPair> replacementsIn,
        List<File> replacementfiles) {
    List<ReplacementPair> replacements = new ArrayList<>(replacementsIn);
    for (File replacementfile : replacementfiles) {
        if (replacementfile.exists()) {
            Properties properties = new Properties();
            try {
                properties.load(new FileInputStream(replacementfile));
            } catch (IOException e) {
                LOG.error(e.getMessage(), e);
                return;
            }//  ww  w . jav a  2  s.  c o  m
            for (Entry<Object, Object> x : properties.entrySet()) {
                replacements
                        .add(new ReplacementPair(((String) x.getKey()).trim(), ((String) x.getValue()).trim()));
            }
        } else {
            LOG.warn("Replacement file {} not found", replacementfile);
        }
    }
    perform(directory, wildcards, replacements);
}

From source file:Log4jPropertyHelper.java

public static void updateLog4jConfiguration(Class<?> targetClass, String log4jPath) throws Exception {
    Properties customProperties = new Properties();
    FileInputStream fs = null;/*from  ww  w . j a  va2  s  .com*/
    InputStream is = null;
    try {
        fs = new FileInputStream(log4jPath);
        is = targetClass.getResourceAsStream("/log4j.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:io.janusproject.Boot.java

private static void parseCommandLineForSystemProperties(CommandLine cmd) {
    if (cmd.hasOption('o')) {
        System.setProperty(JanusConfig.OFFLINE, Boolean.TRUE.toString());
    }//www  .  j  a v  a  2 s .co m
    if (cmd.hasOption('R')) {
        System.setProperty(JanusConfig.BOOT_DEFAULT_CONTEXT_ID_NAME, Boolean.FALSE.toString());
        System.setProperty(JanusConfig.RANDOM_DEFAULT_CONTEXT_ID_NAME, Boolean.TRUE.toString());
    } else if (cmd.hasOption('B')) {
        System.setProperty(JanusConfig.BOOT_DEFAULT_CONTEXT_ID_NAME, Boolean.TRUE.toString());
        System.setProperty(JanusConfig.RANDOM_DEFAULT_CONTEXT_ID_NAME, Boolean.FALSE.toString());
    } else if (cmd.hasOption('W')) {
        System.setProperty(JanusConfig.BOOT_DEFAULT_CONTEXT_ID_NAME, Boolean.FALSE.toString());
        System.setProperty(JanusConfig.RANDOM_DEFAULT_CONTEXT_ID_NAME, Boolean.FALSE.toString());
    }
    // Define the system properties, if not already done by the JRE.
    Properties props = cmd.getOptionProperties("D"); //$NON-NLS-1$
    if (props != null) {
        for (Entry<Object, Object> entry : props.entrySet()) {
            System.setProperty(entry.getKey().toString(), entry.getValue().toString());
        }
    }
}

From source file:io.amient.yarn1.YarnClient.java

public static Properties getAppConfiguration() {
    try {/*from  ww  w. j  av  a  2 s .c  o m*/
        Properties properties = new Properties() {
            {
                load(new FileInputStream("yarn1.configuration"));
            }
        };
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            properties.setProperty(entry.getKey().toString(), entry.getValue().toString());
        }
        return properties;
    } catch (Exception e) {
        log.error("Failed to load localised configuration for yarn1 context", e);
        return null;
    }
}

From source file:com.taobao.tddl.common.util.CountPunisher.java

public static CountPunisher parse(SmoothValve smoothValve, String str) {
    str = str.replaceAll("@@@", LINE_SEP);
    str = str.replaceAll("###", LINE_SEP);
    str = str.replaceAll("$$$", LINE_SEP);
    str = str.replaceAll(";;;", LINE_SEP);
    Properties p = ConfigServerHelper.parseProperties(str, "[CountPunisher Properties]");
    if (p == null) {
        log.warn("Empty tddlconfig");
        return null;
    }/*  w  w  w  .  j  a  va 2 s. c  om*/
    try {
        long timeWindow = -1;
        long limit = -1;
        long resetTime = -1;
        for (Map.Entry<Object, Object> entry : p.entrySet()) {
            String key = ((String) entry.getKey()).trim();
            String value = ((String) entry.getValue()).trim();
            switch (CreateProperties.valueOf(key)) {
            case timeWindow:
                timeWindow = Long.parseLong(value);
                break;
            case limit:
                limit = Long.parseLong(value);
                break;
            case resetTime:
                resetTime = Long.parseLong(value);
                break;
            default:
                break;
            }
        }
        if (timeWindow == -1 || limit == -1) {
            log.error("CountPunisher Properties incomplete");
            return null;
        }
        if (resetTime == -1) {
            return new CountPunisher(smoothValve, timeWindow, limit);
        } else {
            return new CountPunisher(smoothValve, timeWindow, limit, resetTime);
        }
    } catch (Exception e) {
        log.error("parse CountPunisher Properties failed", e);
        return null;
    }
}

From source file:energy.usef.environment.tool.util.FileUtil.java

public static Properties readProperties(String configFilename) throws IOException {
    LOGGER.info("Reading properties file: {}", configFilename);
    Properties properties = new Properties();
    try (FileInputStream input = new FileInputStream(configFilename);) {
        properties.load(input);/*w  w  w .  j a v a  2 s  . c  o  m*/

        StringBuilder sb = new StringBuilder("Properties read from " + configFilename + ":\n");
        for (Entry<Object, Object> entry : properties.entrySet()) {
            sb.append(entry.getKey() + "=" + entry.getValue() + "\n");
        }
        LOGGER.debug(sb.toString());
    }
    return properties;
}

From source file:com.alibaba.napoli.metamorphosis.utils.DiamondUtils.java

/** ??topic?(?topic) */
public static void getPartitions(final Properties properties, final Map<String, List<Partition>> ret) {
    log.info("??");
    final Map<String, List<Partition>> map = new HashMap<String, List<Partition>>();
    if (properties != null) {
        for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
            final String key = (String) entry.getKey();

            if (key != null && key.startsWith("topic.num.")) {
                // key?topic
                final String topic = key.substring("topic.num.".length());
                // value?brokerId0:num0;brokerId1:num1;...
                final String value = (String) entry.getValue();
                final List<Partition> partitions = parsePartitions(value);
                if (partitions != null && !partitions.isEmpty()) {
                    map.put(topic, partitions);
                }//from  w w  w. java2 s .c  om
            }
        }
        ret.clear();
        ret.putAll(map);
        if (!ret.isEmpty()) {
            log.info("?: " + map);
        } else {
            log.info("empty partitionsNum info");
        }
    } else {
        log.warn("Null partitionsNum config");
    }

}

From source file:net.firejack.platform.web.security.x509.KeyUtils.java

public static Map<String, String> getMapProperties(File properties, File keystore) {
    Properties props = getProperties(properties, keystore);
    Map<String, String> propertiesMap = new HashMap<String, String>();
    for (Map.Entry<Object, Object> entry : props.entrySet()) {
        propertiesMap.put((String) entry.getKey(), (String) entry.getValue());
    }/*from ww  w  .  j  a v a  2 s  .  c  o m*/
    return propertiesMap;
}

From source file:com.openideals.android.net.HttpManager.java

public static String uploadFile(String serviceEndpoint, Properties properties, String fileParam, String file)
        throws Exception {

    HttpClient httpClient = new DefaultHttpClient();

    HttpPost request = new HttpPost(serviceEndpoint);
    MultipartEntity entity = new MultipartEntity();

    Iterator<Map.Entry<Object, Object>> i = properties.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) i.next();
        String key = (String) entry.getKey();
        String val = (String) entry.getValue();
        entity.addPart(key, new StringBody(val));
    }//from  w w w .j a va 2 s  .co m
    File upload = new File(file);
    Log.i("httpman", "upload file (" + upload.getAbsolutePath() + ") size=" + upload.length());

    entity.addPart(fileParam, new FileBody(upload));
    request.setEntity(entity);

    HttpResponse response = httpClient.execute(request);
    int status = response.getStatusLine().getStatusCode();

    if (status != HttpStatus.SC_OK) {

    } else {

    }

    return response.toString();

}