Java URI Parse parseQuery(URI uri)

Here you can find the source of parseQuery(URI uri)

Description

parse Query

License

Open Source License

Declaration

private static Map<String, List<String>> parseQuery(URI uri)
            throws UnsupportedEncodingException 

Method Source Code

//package com.java2s;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
import java.util.ArrayList;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class Main {
    private static Map<String, List<String>> parseQuery(URI uri)
            throws UnsupportedEncodingException {
        Map<String, List<String>> query_pairs = new LinkedHashMap<String, List<String>>();
        String query = uri.getQuery();
        if (query == null)
            return new HashMap<String, List<String>>();
        String[] pairs = query.split("&");
        for (String pair : pairs) {
            int idx = pair.indexOf("=");
            String v = URLDecoder.decode(pair.substring(idx + 1), "UTF-8");
            String k = URLDecoder.decode(pair.substring(0, idx), "UTF-8");
            List<String> l = query_pairs.get(k);
            if (l == null) {
                l = new ArrayList<String>();
                query_pairs.put(k, l);/*from   www .  j av  a2  s .co  m*/
            }
            l.add(v);
        }
        return query_pairs;
    }
}

Related

  1. parsePathElements(URI uri)
  2. parsePorts(URI connectionURI)
  3. parseQuery(String uri)
  4. parseQuery(URI aURI, boolean shouldDecode)
  5. parseQuery(URI uri)
  6. parseQueryString(final URI uri, final M queryParams)
  7. parseQueryString(URI uri)
  8. parseQueryString(URI uri, M queryParams)
  9. parseRegionName(URI endpoint)