Java URL Parameter Builder parse_parameters(String input)

Here you can find the source of parse_parameters(String input)

Description

parsparameters

License

Open Source License

Declaration

public static Map<String, List<String>> parse_parameters(String input)
            throws UnsupportedEncodingException 

Method Source Code

//package com.java2s;
/**/*from   w w  w .j  ava2  s  . c o  m*/
 * Class to provide %OAuth utility methods
 *
 * @copyright  Andy Smith
 * @version 2008-08-04
 * @license https://opensource+org/licenses/MIT The MIT License
 */

import java.util.List;
import java.util.Map;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.io.UnsupportedEncodingException;

import java.net.URLDecoder;

public class Main {
    public static Map<String, List<String>> parse_parameters(String input)
            throws UnsupportedEncodingException {
        final Map<String, List<String>> query_pairs = new LinkedHashMap<String, List<String>>();
        final String[] pairs = input.split("&");
        for (String pair : pairs) {
            final int idx = pair.indexOf("=");
            final String key = idx > 0 ? URLDecoder.decode(
                    pair.substring(0, idx), "UTF-8") : pair;
            if (!query_pairs.containsKey(key)) {
                query_pairs.put(key, new LinkedList<String>());
            }
            final String value = idx > 0 && pair.length() > idx + 1 ? URLDecoder
                    .decode(pair.substring(idx + 1), "UTF-8") : null;
            query_pairs.get(key).add(value);
        }
        return query_pairs;
    }
}

Related

  1. mapToFormString(Map map)
  2. mapToStr( Map map)
  3. mapToStr(Map map)
  4. mapToString(Map map)
  5. parse(final Map> parameters, final Scanner scanner, final String encoding)
  6. parseGetParameters(HttpExchange exchange)
  7. parseParameters(final String value)
  8. parseResponseParams(String body)
  9. sendGetRequest(String path, Map params, String enc)