Java URL Encode encode(String value)

Here you can find the source of encode(String value)

Description

encode

License

Open Source License

Parameter

Parameter Description
value a parameter

Declaration

public static String encode(String value) 

Method Source Code

//package com.java2s;

import java.util.Collection;
import java.util.Map;

public class Main {

    public static String encode(String value) {
        if (isEmpty(value)) {
            return "";
        }/*from  w w w .  ja v a2 s  . c  om*/
        try {
            value = java.net.URLEncoder.encode(value, "utf-8");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return value;
    }

    public static boolean isEmpty(String input) {
        return (input == null || input.length() == 0);
    }

    @SuppressWarnings("rawtypes")
    public static boolean isEmpty(Object pObj) {
        if (pObj == null)
            return true;
        if (pObj == "")
            return true;
        if (pObj instanceof String) {
            if (((String) pObj).length() == 0) {
                return true;
            }
        } else if (pObj instanceof Collection) {
            if (((Collection) pObj).size() == 0) {
                return true;
            }
        } else if (pObj instanceof Map) {
            if (((Map) pObj).size() == 0) {
                return true;
            }
        }
        return false;
    }

    public static String isEmpty(String input, String errorMsg) {
        if (isEmpty(input)) {
            return errorMsg;
        }
        return "";
    }
}

Related

  1. encode(String str)
  2. encode(String string)
  3. encode(String strInput)
  4. encode(String text)
  5. encode(String toBeEncoded, String charSet, String defaultReturnValue)
  6. encode(String value)
  7. encode(String value)
  8. encode(String value)
  9. encode(String value, String charset)