Example usage for java.io UnsupportedEncodingException getMessage

List of usage examples for java.io UnsupportedEncodingException getMessage

Introduction

In this page you can find the example usage for java.io UnsupportedEncodingException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:Main.java

public static String URLEncode(String string) {
    try {/*from  w w w  .  j  a  va  2  s  .  c  om*/
        return URLEncoder.encode(string, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new Error(e.getMessage());
    }
}

From source file:Main.java

public static String parseUnicodeString(String source) {
    try {//  ww  w .jav  a  2 s.c  o m
        source = URLDecoder.decode(source, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    }
    return source;
}

From source file:Main.java

public static String encodeUnicodeString(String source) {
    try {//from w w w  . jav a 2  s.  c o  m
        source = URLEncoder.encode(source, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    }
    return source;
}

From source file:Main.java

public static String getUrlEncodeString(String key, String value) {
    String encodeStr = "";

    try {/* w  ww .j  a  v  a  2s  . c  o m*/
        encodeStr = URLEncoder.encode(key, "UTF-8") + "=" + URLEncoder.encode(value, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        Log.e("Encode Error", e.getMessage());
    }

    return encodeStr;
}

From source file:Main.java

public static byte[] getBytes(final String value) {
    try {//from  w ww.jav  a 2  s .c  om
        if (value == null) {
            return new byte[0];
        }
        return value.getBytes("ASCII");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage());
    }
}

From source file:Main.java

public static String decode(String s) {
    if (s == null) {
        return "";
    }/*from   w  ww .  ja  va2 s  .  c o m*/
    try {
        return URLDecoder.decode(s, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:Main.java

public static String encode(String s) {
    if (s == null) {
        return "";
    }/*ww  w .  j  a  v  a2s  .co  m*/
    try {
        return URLEncoder.encode(s, "UTF-8").replace("+", "%20").replace("*", "%2A").replace("%7E", "~")
                .replace("#", "%23");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:com.floreantpos.util.PasswordHasher.java

public static String hashPassword(String password) {
    byte[] passwordBytes = null;
    MessageDigest md = null;/*from   w  w  w.j a  v a 2 s.  c  o  m*/

    try {
        passwordBytes = password.getBytes("UTF-8"); //$NON-NLS-1$
    } catch (UnsupportedEncodingException e) {
        PosLog.error(PasswordHasher.class, e.getMessage());
    }

    try {
        md = MessageDigest.getInstance("SHA1"); //$NON-NLS-1$
    } catch (NoSuchAlgorithmException e) {
        PosLog.error(PasswordHasher.class, e.getMessage());
    }

    byte[] hashBytes = md.digest(passwordBytes);

    return Hex.encodeHexString(hashBytes);

}

From source file:Main.java

public static String md5(String string) {
    if (string == null || string.trim().length() < 1) {
        return null;
    }//from w  w  w .  j  a  v a2s .  c o m
    try {
        return getMD5(string.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:Main.java

public static String getPostDataString(HashMap<String, String> params) {
    try {/*w w w .j  a  va 2 s  .c  o m*/
        StringBuilder result = new StringBuilder();
        boolean first = true;

        for (Map.Entry<String, String> entry : params.entrySet()) {
            if (first)
                first = false;
            else
                result.append("&");

            result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
            result.append("=");
            if (entry.getValue() == null) {
                result.append(URLEncoder.encode("", "UTF-8"));
            } else {
                result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
            }

        }
        return result.toString();
    } catch (UnsupportedEncodingException e) {
        System.out.print(e.getMessage());
    }
    return "";
}