Java URL Query Parse parseParameters( Optional queryString)

Here you can find the source of parseParameters( Optional queryString)

Description

parse Parameters

License

Open Source License

Declaration

public static Map<String, String[]> parseParameters(
            Optional<String> queryString) 

Method Source Code

//package com.java2s;
/* (c) 2016 Open Source Geospatial Foundation - all rights reserved
 * This code is licensed under the GPL 2.0 license, available at the root
 * application directory.//from   w w w  .jav  a  2 s . co  m
 */

import java.net.URLDecoder;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public class Main {
    public static Map<String, String[]> parseParameters(
            Optional<String> queryString) {
        Map<String, String[]> parameters = new HashMap<>();
        if (!queryString.isPresent()) {
            return parameters;
        }
        final String[] parametersParts = queryString.get().split("&");
        for (String parametersPart : parametersParts) {
            String[] parameterParts = parametersPart.split("=");
            if (parameterParts.length < 2) {
                continue;
            }
            String name = URLDecoder.decode(parameterParts[0]);
            String value = URLDecoder.decode(parameterParts[1]);
            String[] values = parameters.get(name);
            if (values == null) {
                parameters.put(name, new String[] { value });
            } else {
                values = Arrays.copyOf(values, value.length() + 1);
                values[value.length()] = value;
                parameters.put(name, values);
            }
        }
        return parameters;
    }
}

Related

  1. parse(String query, String encoding)
  2. parseInstructions(final String query)
  3. parseParameters(String query)
  4. parseQuery(String query)
  5. parseQuery(String query)
  6. parseQuery(String query)