Here you can find the source of queryString(final Map
Parameter | Description |
---|---|
params | Query parameters |
private static String queryString(final Map<String, List<String>> params)
//package com.java2s; /**//from w w w .ja v a 2 s . co m * Copyright 2014 DuraSpace, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Iterator; import java.util.List; import java.util.Map; public class Main { /** * Encode URL parameters as a query string. * @param params Query parameters **/ private static String queryString(final Map<String, List<String>> params) { final StringBuilder builder = new StringBuilder(); if (params != null && params.size() > 0) { for (final Iterator<String> it = params.keySet().iterator(); it.hasNext();) { final String key = it.next(); final List<String> values = params.get(key); for (final String value : values) { try { builder.append(key + "=" + URLEncoder.encode(value, "UTF-8") + "&"); } catch (final UnsupportedEncodingException e) { builder.append(key + "=" + value + "&"); } } } return builder.length() > 0 ? "?" + builder.substring(0, builder.length() - 1) : ""; } return ""; } }