Java URL Parameter Builder mapToStr(Map map)

Here you can find the source of mapToStr(Map map)

Description

Creates an encoded String from a Map of name/value pairs (MUST BE STRINGS!)

License

Open Source License

Parameter

Parameter Description
map The Map of name/value pairs

Return

String The encoded String

Declaration

public static String mapToStr(Map<String, String> map) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.URLEncoder;

import java.util.Iterator;

import java.util.Map;

import java.util.Set;

public class Main {
    /**// w  ww .j  a  v a2s.c o m
     * Creates an encoded String from a Map of name/value pairs (MUST BE
     * STRINGS!)
     * 
     * @deprecated
     * @param map
     *            The Map of name/value pairs
     * @return String The encoded String
     */
    public static String mapToStr(Map<String, String> map) {
        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();
            Object value = map.get(key);
            if (!(key instanceof String) || !(value instanceof String))
                continue;
            String encodedName = URLEncoder.encode((String) key);
            String encodedValue = URLEncoder.encode((String) value);

            if (first)
                first = false;
            else
                buf.append("|");

            buf.append(encodedName);
            buf.append("=");
            buf.append(encodedValue);
        }
        return buf.toString();
    }
}

Related

  1. getURLParameters(URI uri)
  2. map2String(Map params)
  3. mapToFormEncodedString(Map data)
  4. mapToFormString(Map map)
  5. mapToStr( Map map)
  6. mapToString(Map map)
  7. parse(final Map> parameters, final Scanner scanner, final String encoding)
  8. parse_parameters(String input)
  9. parseGetParameters(HttpExchange exchange)