Java URL Decode addParam(Map properties, String strParams, boolean bDecodeString)

Here you can find the source of addParam(Map properties, String strParams, boolean bDecodeString)

Description

Parse the param line and add it to this properties object.

License

Open Source License

Parameter

Parameter Description
strParam param line in the format param=value

Declaration

public static void addParam(Map<String, Object> properties, String strParams, boolean bDecodeString) 

Method Source Code


//package com.java2s;
import java.net.URLDecoder;

import java.util.Map;

public class Main {
    public final static String URL_ENCODING = "UTF-8";

    /**/*from  w  w w. ja v  a 2 s. c  o  m*/
     * Parse the param line and add it to this properties object.
     * (ie., key=value).
     * @properties The properties object to add this params to.
     * @param strParam param line in the format param=value
     */
    public static void addParam(Map<String, Object> properties, String strParams, boolean bDecodeString) {
        int iIndex = strParams.indexOf('=');
        int iEndIndex = strParams.length();
        if (iIndex != -1) {
            String strParam = strParams.substring(0, iIndex);
            String strValue = strParams.substring(iIndex + 1, iEndIndex);
            if (bDecodeString) {
                try {
                    strParam = URLDecoder.decode(strParam, URL_ENCODING);
                    strValue = URLDecoder.decode(strValue, URL_ENCODING);
                } catch (java.io.UnsupportedEncodingException ex) {
                    ex.printStackTrace();
                }
            }
            properties.put(strParam, strValue);
        }
    }
}

Related

  1. decode( Map source, String encoding)
  2. decode(final String content, final String encoding)
  3. decode(final String s, final String enc)
  4. decode(final String string)