Here you can find the source of parseParameters(final String value)
static Map<String, String> parseParameters(final String value)
//package com.java2s; /* Utils.java/*from ww w .ja v a 2s. c o m*/ * * Created: 2012-10-01 (Year-Month-Day) * Character encoding: UTF-8 * ****************************************** LICENSE ******************************************* * * Copyright (c) 2012 - 2013 XIAM Solutions B.V. (http://www.xiam.nl) * * 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 java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { /** * The canonical character set name for {@code UTF-8}. * {@code UTF-8} is the only character set used by JSON. */ static final String UTF8 = "UTF-8"; private static final Pattern KEY_VALUES = Pattern.compile("([^&]+)=([^&]+)"); /** * Parse the given {@code application/x-www-form-urlencoded} String and return the * parameters as a (name/value) Map. If the String is empty or {@code null} an empty * Map is returned. */ static Map<String, String> parseParameters(final String value) { if (value == null || value.isEmpty()) { return Collections.emptyMap(); } final Map<String, String> map = new HashMap<String, String>(); final Matcher m = KEY_VALUES.matcher(value); while (m.find()) { map.put(decodeRfc5849(m.group(1)), decodeRfc5849(m.group(2))); } return map; } /** * Percent decodeRfc5849 the value as specified by the RFC5849 (3.6). */ static String decodeRfc5849(final String value) { try { return URLDecoder.decode(value, UTF8); } catch (UnsupportedEncodingException ex) { throw new AssertionError(ex); // UTF-8 is always supported } } }