Java Utililty Methods URL Parameter Builder

List of utility methods to do URL Parameter Builder

Description

The list of methods to do URL Parameter Builder are organized into topic(s).

Method

MapgetURLParameters(URI uri)
get URL Parameters
if (uri == null) {
    return null;
String query = uri.getQuery();
if (query == null) {
    return null;
Map parameters = new HashMap();
...
Stringmap2String(Map params)
map String
int count = 0;
StringBuilder builder = new StringBuilder();
for (Entry<String, String> entry : params.entrySet()) {
    if (count > 0) {
        builder.append("&");
    builder.append(entry.getKey());
    builder.append("=");
...
StringmapToFormEncodedString(Map data)
map To Form Encoded String
final List<String> acc = new ArrayList<String>();
for (Map.Entry<String, String> entry : data.entrySet()) {
    acc.add(encodeURIComponent(entry.getKey()) + "=" + encodeURIComponent(entry.getValue()));
return "?" + join(acc, "&");
StringmapToFormString(Map map)
map To Form String
StringBuilder postDataStringBuilder = new StringBuilder();
String postDataString;
try {
    for (Map.Entry<String, String> entry : map.entrySet()) {
        postDataStringBuilder.append(URLEncoder.encode(entry.getKey(), "UTF-8")).append("=")
                .append(URLEncoder.encode(entry.getValue(), "UTF-8")).append("&");
} catch (Exception e) {
...
StringmapToStr(Map map)
Creates an encoded String from a Map of name/value pairs (MUST BE STRINGS!)
if (map == null)
    return null;
StringBuilder buf = new StringBuilder();
boolean first = true;
for (Map.Entry<? extends Object, ? extends Object> entry : map.entrySet()) {
    Object key = entry.getKey();
    Object value = entry.getValue();
    if (!(key instanceof String) || !(value instanceof String))
...
StringmapToStr(Map map)
Creates an encoded String from a Map of name/value pairs (MUST BE STRINGS!)
if (map == null)
    return null;
StringBuffer buf = new StringBuffer();
Set<String> keySet = map.keySet();
Iterator<String> i = keySet.iterator();
boolean first = true;
while (i.hasNext()) {
    Object key = i.next();
...
StringmapToString(Map map)
map To String
StringBuilder stringBuilder = new StringBuilder();
for (String key : map.keySet()) {
    if (stringBuilder.length() > 0) {
        stringBuilder.append("&");
    String value = map.get(key);
    try {
        stringBuilder.append((key != null ? URLEncoder.encode(key, "UTF-8") : ""));
...
voidparse(final Map> parameters, final Scanner scanner, final String encoding)
Adds all parameters within the Scanner to the list of parameters, as encoded by encoding.
scanner.useDelimiter(PARAMETER_SEPARATOR);
while (scanner.hasNext()) {
    final String[] nameValue = scanner.next().split(NAME_VALUE_SEPARATOR);
    if (nameValue.length == 0 || nameValue.length > 2)
        throw new IllegalArgumentException("bad parameter");
    final String name = decode(nameValue[0], encoding);
    String value = null;
    if (nameValue.length == 2)
...
Map>parse_parameters(String input)
parsparameters
final Map<String, List<String>> query_pairs = new LinkedHashMap<String, List<String>>();
final String[] pairs = input.split("&");
for (String pair : pairs) {
    final int idx = pair.indexOf("=");
    final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), "UTF-8") : pair;
    if (!query_pairs.containsKey(key)) {
        query_pairs.put(key, new LinkedList<String>());
    final String value = idx > 0 && pair.length() > idx + 1
            ? URLDecoder.decode(pair.substring(idx + 1), "UTF-8")
            : null;
    query_pairs.get(key).add(value);
return query_pairs;
voidparseGetParameters(HttpExchange exchange)
parse Get Parameters
Map<String, Object> parameters = new HashMap<String, Object>();
URI requestedUri = exchange.getRequestURI();
String query = requestedUri.getRawQuery();
parseQuery(query, parameters);
exchange.setAttribute("parameters", parameters);