Java String Encode encodeState(Map params)

Here you can find the source of encodeState(Map params)

Description

encode State

License

Open Source License

Declaration

public static String encodeState(Map<String, String> params) 

Method Source Code


//package com.java2s;
/*// w  w w .jav a 2s .  com
 * Copyright (c) 2013, Helome and/or its affiliates. All rights reserved.
 * Helome PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 * Created on 2014-3-26
 */

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;

import java.util.Map;

public class Main {

    public static String encodeState(Map<String, String> params) {
        String state = null;

        try {
            StringBuilder stateBuilder = new StringBuilder();
            for (Map.Entry<String, String> e : params.entrySet()) {
                stateBuilder.append(URLEncoder.encode(e.getKey(), "utf-8")).append('&');
                stateBuilder.append(URLEncoder.encode(e.getValue(), "utf-8")).append('&');
            }

            if (stateBuilder.length() > 0) {
                stateBuilder.deleteCharAt(stateBuilder.length() - 1);
            }

            state = URLEncoder.encode(stateBuilder.toString(), "utf-8").replace('%', '_');
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }

        return state;
    }
}

Related

  1. EncodePath(String path)
  2. encodePath(String path)
  3. encodePath(String str)
  4. encodeRfc5849(final String value)
  5. encodeSpecialMdxCharactersInNames(String name)
  6. encodeStr(String str)
  7. encodeStr(String str)
  8. encodeStr(String t)
  9. encodeString(final String string)