Java URL Query Split splitQuery(String query)

Here you can find the source of splitQuery(String query)

Description

split Query

License

Apache License

Declaration

public static Multimap<String, String> splitQuery(String query) throws UnsupportedEncodingException 

Method Source Code


//package com.java2s;
/*/*from   w  ww.ja v a 2 s .c o  m*/
 * Copyright (C) 2015 The Calrissian Authors
 *
 * 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 com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;

public class Main {
    public static Multimap<String, String> splitQuery(String query) throws UnsupportedEncodingException {
        Multimap<String, String> query_pairs = LinkedListMultimap.create();
        String[] pairs = query.split("&");
        for (String pair : pairs) {
            int idx = pair.indexOf("=");
            query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"),
                    URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
        }
        return query_pairs;
    }

    public static Multimap<String, String> splitQuery(URI uri) throws UnsupportedEncodingException {
        return splitQuery(uri.getQuery());
    }
}

Related

  1. splitQuery(String query)
  2. splitQuery(String queryString)
  3. splitQuery(String url)
  4. splitQuery(URL url)