Java URI to Parent URI getParams(URI uri)

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

Description

get Params

License

Apache License

Declaration

public static Map<String, String> getParams(URI uri) throws UnsupportedEncodingException 

Method Source Code

//package com.java2s;
/**//from  w  w w . j av  a 2  s  .  c o m
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.Maps;
import java.io.UnsupportedEncodingException;
import java.net.URI;

import java.util.Map;

public class Main {
    public static Map<String, String> getParams(URI uri) throws UnsupportedEncodingException {
        return getParamsFromQuery(uri.getQuery());
    }

    /**
     * It parses a query string into key/value pairs
     *
     * @param queryString decoded query string
     * @return key/value pairs parsed from a given query string
     * @throws UnsupportedEncodingException
     */
    public static Map<String, String> getParamsFromQuery(String queryString) throws UnsupportedEncodingException {
        String[] queries = queryString.split("&");

        Map<String, String> params = Maps.newHashMap();
        String[] param;
        for (String q : queries) {
            param = q.split("=");
            params.put(param[0], param[1]);
        }

        return params;
    }
}

Related

  1. getParent(final URI uri)
  2. getParent(URI path)
  3. getParent(URI uri)
  4. getParentName(URI uri)