Example usage for java.util HashMap putAll

List of usage examples for java.util HashMap putAll

Introduction

In this page you can find the example usage for java.util HashMap putAll.

Prototype

public void putAll(Map<? extends K, ? extends V> m) 

Source Link

Document

Copies all of the mappings from the specified map to this map.

Usage

From source file:cn.garymb.wechatmoments.common.OkHttpStack.java

@Override
@SuppressWarnings("deprecation")
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap<>();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);//from   w  w  w. j  av  a 2 s .  c  om
    if (mUrlRewriter != null) {
        String rewritten = mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    URL parsedUrl = new URL(url);
    OkUrlFactory okFactory = new OkUrlFactory(mClient);
    HttpURLConnection connection = openOkHttpURLConnection(okFactory, parsedUrl, request);
    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }
    setConnectionParametersForRequest(connection, request);
    // Initialize HttpResponse with data from the HttpURLConnection.
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    int responseCode = connection.getResponseCode();
    if (responseCode == -1) {
        // -1 is returned by getResponseCode() if the response code could not be retrieved.
        // Signal to the caller that something was wrong with the connection.
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection.getResponseCode(),
            connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(entityFromConnection(connection));
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);
        }
    }
    return response;
}

From source file:net.itransformers.idiscover.v2.core.node_discoverers.snmpdiscoverer.SnmpParallelNodeDiscoverer.java

@Override
public NodeDiscoveryResult discover(ConnectionDetails connectionDetails) {
    String deviceId = null;/*  w ww  .j  a  va 2  s .co m*/

    String deviceName = connectionDetails.getParam("deviceName");
    String ipAddressStr = connectionDetails.getParam("ipAddress");
    String deviceType = connectionDetails.getParam("deviceType");
    Map<String, String> resourceSelectionParams = returnResourceSelectionParams(deviceName, deviceType,
            ipAddressStr);

    HashMap<String, String> resultParams = new HashMap<>();
    NodeDiscoveryResult result = new NodeDiscoveryResult();

    SnmpManager snmpManager = null;
    try {
        snmpManager = getSnmpManager(resourceSelectionParams, ipAddressStr);
    } catch (IOException e) {
        logger.error(e.getMessage());
    }

    if (snmpManager != null) {
        String hostNameBySnmp = null;
        String deviceTypeBySnmp;

        try {
            String deviceSysDescr = snmpManager.snmpGet("1.3.6.1.2.1.1.1.0");
            String hostNameBySnmpStr1 = snmpManager.snmpGet("1.3.6.1.2.1.1.5.0");

            if (hostNameBySnmpStr1 != null) {
                if (hostNameBySnmpStr1.contains("."))
                    hostNameBySnmp = StringUtils.substringBefore(hostNameBySnmpStr1, ".");
                else
                    hostNameBySnmp = hostNameBySnmpStr1;
            } else {
                logger.info(
                        "Can't determine the hostname of " + ipAddressStr + " with " + resourceSelectionParams);

                return null;
            }
            deviceTypeBySnmp = DeviceTypeResolver.getDeviceType(deviceSysDescr);

            resultParams.put("hostName", hostNameBySnmp);
            resultParams.put("deviceType", deviceTypeBySnmp);
            resultParams.put("sysDescr", deviceSysDescr);
        } catch (IOException ioe) {
            logger.error(ioe.getMessage());
            return null;

        }

        deviceId = hostNameBySnmp;

        DiscoveryHelper discoveryHelper = discoveryHelperFactory.createDiscoveryHelper(deviceTypeBySnmp);

        XmlDiscoveryHelperV2 discoveryHelperV2 = createXmlDiscoveryHelper(deviceTypeBySnmp);

        RawDeviceData rawData = getRawData(snmpManager, discoveryHelper);
        try {
            snmpManager.closeSnmp();
        } catch (IOException e) {
            e.printStackTrace();
        }
        DiscoveredDeviceData discoveredDeviceData = getDeviceData(discoveryHelper, rawData);
        DiscoveredDevice discoveredDevice = discoveryHelperV2.createDevice(discoveredDeviceData, deviceId);

        HashMap<String, String> deviceParams = discoveredDevice.getParams();
        deviceParams.putAll(resultParams);
        discoveredDevice.setParams(deviceParams);

        List<DeviceNeighbour> neighbours = discoveredDevice.getDeviceNeighbours();
        Set<Subnet> subnets = discoveredDevice.getDeviceSubnetsFromActiveInterfaces();
        Set<ConnectionDetails> ownConnectionDetails = discoveredDevice.getDeviceOwnConnectionDetails();
        Set<ConnectionDetails> neighboursConnDetails = new HashSet<ConnectionDetails>();

        if (neighbours != null) {
            NeighbourConnectionDetails neighbourConnectionDetails = new NeighbourConnectionDetails(neighbours);
            neighboursConnDetails = neighbourConnectionDetails.getConnectionDetailses();
        }

        if (subnets != null) {
            SubnetConnectionDetails subnetConnectionDetails1 = new SubnetConnectionDetails();
            subnetConnectionDetails1.load(subnets);
            neighboursConnDetails.addAll(subnetConnectionDetails1.getSubnetConnectionDetails());
        }

        result.setOwnConnectionDetails(ownConnectionDetails);
        result.setNeighboursConnectionDetails(neighboursConnDetails);
        result.setDiscoveredData("deviceData", discoveredDeviceData);
        result.setDiscoveredData("DiscoveredDevice", discoveredDevice);
        result.setDiscoveredData("rawData", rawData.getData());
        result.setNodeId(deviceId);
        return result;

    } else {
        return null;

    }
}

From source file:org.formic.ant.TemplateTask.java

public void execute() throws BuildException {
    if (template == null || out == null) {
        throw new BuildException("Both template and out attributes must be supplied");
    }//w w  w .  ja va 2s.  c o  m

    if (template.equals(out)) {
        out = new File(out.getAbsolutePath() + ".out");
        move = true;
    }

    HashMap values = new HashMap();

    values.put(TemplateStepAction.INSTALLER_KEY, TemplateStepAction.INSTALLER);
    values.put(TemplateStepAction.OS_KEY, TemplateStepAction.OS);
    values.putAll(getProject().getProperties());

    FileReader reader = null;
    FileWriter writer = null;
    try {
        log("Evaluating template: " + template);
        reader = new FileReader(this.template);
        writer = new FileWriter(this.out);
        VelocityContext context = new VelocityContext(values);
        Velocity.evaluate(context, writer, TemplateTask.class.getName(), reader);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(reader);
        IOUtils.closeQuietly(writer);
    }

    if (move) {
        Move move = new Move();
        move.setProject(getProject());
        move.setTaskName(getTaskName());
        move.setFile(out);
        move.setTofile(template);
        move.execute();
    }
}

From source file:contrail.correct.InvokeQuakeForMatePairs.java

protected Map<String, ParameterDefinition> createParameterDefinitions() {
    HashMap<String, ParameterDefinition> defs = new HashMap<String, ParameterDefinition>();
    defs.putAll(super.createParameterDefinitions());
    ParameterDefinition quakeBinary = new ParameterDefinition("quake_binary", "any" + "Quake binary location",
            String.class, new String(""));
    ParameterDefinition bithashpath = new ParameterDefinition("bithashpath", "any" + "The path of bithash ",
            String.class, new String(""));
    ParameterDefinition K = new ParameterDefinition("K", "any" + "Kmer length", Long.class, 0);
    for (ParameterDefinition def : new ParameterDefinition[] { quakeBinary, bithashpath, K }) {
        defs.put(def.getName(), def);// w  w w.  jav a  2 s. c  o m
    }
    for (ParameterDefinition def : ContrailParameters.getInputOutputPathOptions()) {
        defs.put(def.getName(), def);
    }
    return Collections.unmodifiableMap(defs);
}

From source file:org.eclipse.smila.connectivity.framework.impl.CrawlerControllerImpl.java

/**
 * {@inheritDoc}//w  w w. java2  s . c  o  m
 * 
 * @see org.eclipse.smila.connectivity.framework.CrawlerController#getAgentTasksState()
 */
public Map<String, CrawlState> getCrawlerTasksState() {
    final HashMap<String, CrawlState> states = new HashMap<String, CrawlState>();
    states.putAll(_crawlStates);
    return states;
}

From source file:com.ab.network.toolbox.HurlStack.java

@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap<String, String>();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);//from w  w w .j av a2  s  .  c om
    if (mUrlRewriter != null) {
        String rewritten = mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    URL parsedUrl = new URL(url);
    HttpURLConnection connection = openConnection(parsedUrl, request);
    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }
    setConnectionParametersForRequest(connection, request);
    // Initialize HttpResponse with data from the HttpURLConnection.
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    int responseCode = connection.getResponseCode();
    if (responseCode == -1) {
        // -1 is returned by getResponseCode() if the response code could not be retrieved.
        // Signal to the caller that something was wrong with the connection.
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection.getResponseCode(),
            connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(entityFromConnection(connection));
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);
        }
    }
    return response;
}

From source file:org.openqa.selenium.os.OsProcess.java

private Map<String, String> getMergedEnv() {
    HashMap<String, String> newEnv = Maps.newHashMap(System.getenv());
    newEnv.putAll(env);
    return newEnv;
}

From source file:net.di2e.ecdr.libs.result.relevance.RelevanceNormalizer.java

protected Map<String, String> getFilterParameters(Query originalQuery) {
    HashMap<String, String> map = new HashMap<>();
    try {/*from w w  w . j  a v a  2 s .c o m*/
        map.putAll(filterAdapter.adapt(originalQuery, new StrictFilterDelegate(false, SupportedGeosOptions.ALL,
                Collections.<String, String>emptyMap(), Collections.<String, String>emptyMap())));
    } catch (UnsupportedQueryException uqe) {
        LOGGER.debug(
                "Query did not contain any contextual criteria (search phrases), cannot perform re-relevance on this query.");
    }
    return map;
}

From source file:com.coroptis.coidi.core.message.AbstractMessage.java

protected Map<String, String> getMap() {
    HashMap<String, String> out = new HashMap<String, String>();
    out.putAll(map);
    return out;/*from  www  .ja v  a2  s .com*/
}

From source file:com.mojio.mojiosdk.networking.MojioRequest.java

@Override
public Map<String, String> getHeaders() throws AuthFailureError {
    DataStorageHelper oauth = new DataStorageHelper(this.mAppContext);
    HashMap<String, String> headers = new HashMap<String, String>();
    headers.putAll(super.getHeaders());

    // Check for auth token
    // Start with user auth, if that does not exist, check for app auth
    String mojioAuth = oauth.GetAccessToken();
    if (mojioAuth == null) {
        mojioAuth = oauth.GetAppToken();
    }// w  w w  .j a v a 2 s.c  o m
    if (mojioAuth != null) {
        headers.put("MojioAPIToken", mojioAuth);
    }
    if (imageByteArray != null) {
        String body = String.format("\"%s\"", this.contentBody);
        headers.put("Content-Type", "application/json; charset=utf-8");
        headers.put("Content-Length", String.valueOf(body.length()));
    }

    // TODO may want to init MojioClient WITH access token. This would make the app responsible for storing token data.
    Log.i("MOJIO", "Adding headers: " + headers.toString());
    return headers;
}