Java Utililty Methods String Encode

List of utility methods to do String Encode

Description

The list of methods to do String Encode are organized into topic(s).

Method

StringencodeState(Map params)
encode State
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) {
...
StringencodeStr(String str)
encode Str
try {
    str = URLEncoder.encode(str, ENCODE_CHARACTERSET);
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
return str;
StringencodeStr(String str)
encode Str
try {
    return new String(str.getBytes("ISO-8859-1"), "UTF-8");
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    return null;
StringencodeStr(String t)
Translates a string into x-www-form-urlencoded format
return URLEncoder.encode(t);
StringencodeString(final String string)
Encodes a string into Base64 format.
String encodedString = null;
try {
    encodedString = encodeString(string, "UTF-8");
} catch (UnsupportedEncodingException uue) {
return encodedString;
voidencodeString(OutputStream out, String str)
encode String
encodeBytes(out, str.getBytes("ASCII"));
StringencodeString(String b)
encode String
return new String(encode(b.getBytes()));
byte[]encodeString(String in)
Encode a string into the current character set.
byte[] rv = null;
try {
    rv = in.getBytes(charset);
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException(e);
return rv;
StringencodeString(String myString)
encode String
if (myString == null) {
    throw new NullPointerException("encodeString: myString == null!");
try {
    return java.net.URLEncoder.encode(myString, "UTF-8");
} catch (UnsupportedEncodingException ex) {
    throw new AssertionError("UTF-8 not supported");
StringencodeString(String s)
Encodes string to be URL safe.
try {
    return URLEncoder.encode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException("string encoding failed", e);