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:info.guardianproject.net.http.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));

    }//  ww w. j  a v  a 2s .c o  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();

}

From source file:org.apache.camel.component.salesforce.AnalyticsApiIntegrationTest.java

@BeforeClass
public static void getReportNames() throws Exception {
    // get test report names
    Properties testProperties = new Properties();
    testProperties.load(new FileInputStream(LoginConfigHelper.TEST_LOGIN_PROPERTIES));

    Map<String, String> reports = new TreeMap<String, String>();
    for (Map.Entry<Object, Object> entry : testProperties.entrySet()) {
        final String key = entry.getKey().toString();
        if (key.matches("report.[0-9]+")) {
            reports.put(key, entry.getValue().toString());
        }//from   ww  w  .j ava 2  s  . c  om
    }
    assertFalse("Missing entries report.[0-9]+=<Report DeveloperName> in "
            + LoginConfigHelper.TEST_LOGIN_PROPERTIES, reports.isEmpty());

    final Collection<String> reportNames = reports.values();
    testReportNames = reportNames.toArray(new String[reportNames.size()]);
}

From source file:jp.terasoluna.fw.util.PropertyUtil.java

/**
 * ???/*from   w w w  .  j  a v  a2 s. c  o  m*/
 * <p>
 * ????? ?????
 * </p>
 * @param name ??
 */
private static void load(String name) {
    StringBuilder key = new StringBuilder();
    Properties p = readPropertyFile(name);
    for (@SuppressWarnings("rawtypes")
    Map.Entry e : p.entrySet()) {
        // ??????props??
        props.put((String) e.getKey(), (String) e.getValue());
    }

    if (p != null) {
        for (int i = 1;; i++) {
            key.setLength(0);
            key.append(ADD_PROPERTY_PREFIX);
            key.append(i);
            String addfile = p.getProperty(key.toString());
            if (addfile == null) {
                break;
            }
            String path = getPropertiesPath(name, addfile);
            addPropertyFile(path);
        }
    }
}

From source file:com.iisigroup.cap.mvc.i18n.MessageBundleScriptCreator.java

/**
 * properties?json?//from w ww  .  ja  v a2  s .  c  o  m
 *
 * @param props
 *            properties
 * @param filterList
 *            filter
 * @return String
 */
public static String generateJson(Properties props, Set<String> filterList) {
    AjaxFormResult result = new AjaxFormResult();
    String filterReg = generateFilterReg(filterList);
    if (props != null && !props.isEmpty()) {
        if (CapString.isEmpty(filterReg)) {
            for (Entry<Object, Object> entry : props.entrySet()) {
                result.set((String) entry.getKey(), (String) entry.getValue());
            }
        } else {
            for (Entry<Object, Object> entry : props.entrySet()) {
                if (CapString.checkRegularMatch((String) entry.getKey(), filterReg)) {
                    result.set(((String) entry.getKey()).replaceAll("js.", ""), (String) entry.getValue());
                }
            }
        }
    }
    return result.getResult();
}

From source file:io.apiman.gateway.test.junit.servlet.ServletGatewayTestServer.java

/**
 * Configures the gateway by settings system properties.
 *///from   w w w  . j  a v a2 s . c  o m
protected static void configureGateway(JsonNode config) {
    Map<String, String> props = new HashMap<>();

    // Global settings - all tests share but can override
    props.put(GatewayConfigProperties.PLUGIN_REGISTRY_CLASS, DefaultPluginRegistry.class.getName());
    props.put(GatewayConfigProperties.PLUGIN_REGISTRY_CLASS + ".pluginsDir",
            new File("target/plugintmp").getAbsolutePath());
    props.put(GatewayConfigProperties.CONNECTOR_FACTORY_CLASS, HttpConnectorFactory.class.getName());
    props.put(GatewayConfigProperties.POLICY_FACTORY_CLASS, PolicyFactoryImpl.class.getName());
    props.put(GatewayConfigProperties.COMPONENT_PREFIX + IPolicyFailureFactoryComponent.class.getSimpleName(),
            PolicyFailureFactoryComponent.class.getName());
    props.put(GatewayConfigProperties.COMPONENT_PREFIX + IHttpClientComponent.class.getSimpleName(),
            HttpClientComponentImpl.class.getName());
    props.put(GatewayConfigProperties.COMPONENT_PREFIX + IBufferFactoryComponent.class.getSimpleName(),
            ByteBufferFactoryComponent.class.getName());
    props.put(GatewayConfigProperties.METRICS_CLASS, TestMetrics.class.getName());

    // First, process the config files.
    if (config.has("config-files")) {
        JsonNode configFilesNode = config.get("config-files");
        for (JsonNode jsonNode : configFilesNode) {
            String configFile = jsonNode.asText();
            Properties loadedProps = loadConfigFile(configFile);
            for (Entry<Object, Object> entry : loadedProps.entrySet()) {
                props.put(entry.getKey().toString(), entry.getValue().toString());
            }
        }
    }

    // Then layer on top of that, the properties defined in the config itself.
    if (config.has("config-properties")) {
        JsonNode configNode = config.get("config-properties");
        Iterator<String> fieldNames = configNode.fieldNames();
        while (fieldNames.hasNext()) {
            String fieldName = fieldNames.next();
            String value = configNode.get(fieldName).asText();
            props.put(fieldName, value);
        }
    }

    for (Entry<String, String> entry : props.entrySet()) {
        TestUtil.setProperty(entry.getKey(), entry.getValue());
    }
}

From source file:org.apache.lens.server.LensServer.java

/**
 * Print message from lens-build-info file during startup.
 *//*  www . j  a  va  2s .c  om*/
private static void printStartupMessage() {
    StringBuilder buffer = new StringBuilder();
    buffer.append(SEP_LINE);
    buffer.append("                    Lens Server (STARTUP)");
    Properties buildProperties = new Properties();
    InputStream buildPropertiesResource = LensServer.class.getResourceAsStream("/lens-build-info.properties");
    if (buildPropertiesResource != null) {
        try {
            buildProperties.load(buildPropertiesResource);
            for (Map.Entry entry : buildProperties.entrySet()) {
                buffer.append('\n').append('\t').append(entry.getKey()).append(":\t").append(entry.getValue());
            }
        } catch (Throwable e) {
            buffer.append("*** Unable to get build info ***");
        }
    } else {
        buffer.append("*** Unable to get build info ***");
    }
    buffer.append(SEP_LINE);
    LOG.info(buffer.toString());
}

From source file:com.yourmediashelf.fedora.cargo.FedoraHome.java

/**
 * Loads a Map from the given Properties file.
 *
 * @param props//from   ww  w . j  av a 2  s  .  com
 *        the Properties file to parse.
 * @return a Map<String, String> representing the given Properties file.
 * @throws IOException
 * @see java.util.Properties
 * @see java.util.Map
 */
public static Map<String, String> loadMap(Properties props) throws IOException {
    Map<String, String> map = new HashMap<String, String>();
    Set<Entry<Object, Object>> entrySet = props.entrySet();
    for (Entry<Object, Object> entry : entrySet) {
        // The casts to String should always succeed
        map.put((String) entry.getKey(), (String) entry.getValue());
    }
    return map;
}

From source file:com.alexholmes.hdfsslurper.Configurator.java

public static Map<String, String> loadProperties(String path) throws IOException {
    InputStream is = new FileInputStream(path);
    Properties properties = new Properties();
    properties.load(is);//from  w  w w.  j a v a 2  s.  c om
    is.close();

    Map<String, String> props = new HashMap<String, String>();
    for (Map.Entry entry : properties.entrySet()) {
        props.put(entry.getKey().toString(), entry.getValue().toString());
    }
    return props;
}

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

public static SmoothValve parse(String str) {
    Properties p = ConfigServerHelper.parseProperties(str, "[SmoothValve Properties]");
    if (p == null) {
        log.warn("Empty tddlconfig");
        return null;
    }//from   w  ww. j a va 2s . c o m
    try {
        long td = 0;
        String[] limits = null;
        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 timeDelay:
                td = Integer.parseInt(value);
                break;
            case batchLimits:
                limits = value.split("\\|");
                break;
            default:
                break;
            }
        }
        if (td == 0) {
            log.error("SmoothValve Properties incomplete");
            return null;
        }
        if (limits != null) {
            int[] limitArray = new int[limits.length];
            for (int i = 0; i < limits.length; i++) {
                limitArray[i] = Integer.parseInt(limits[i].trim());
            }
            return new SmoothValve(td, limitArray);
        } else {
            return new SmoothValve(td);
        }

    } catch (Exception e) {
        log.error("parse SmoothValve Properties failed", e);
        return null;
    }
}

From source file:net.firejack.platform.core.utils.MiscUtils.java

/**
 * @param properties/* ww  w.  ja v a2 s .  com*/
 * @return
 */
public static Map<String, String> getProperties(File properties) {
    if (properties == null || !properties.exists()) {
        return Collections.emptyMap();
    }
    Properties props = new Properties();
    FileInputStream stream = null;
    try {
        stream = new FileInputStream(properties);
        props.load(stream);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(stream);
    }

    Map<String, String> propertiesMap = new HashMap<String, String>();
    for (Map.Entry<Object, Object> entry : props.entrySet()) {
        propertiesMap.put((String) entry.getKey(), (String) entry.getValue());
    }

    return propertiesMap;
}