Example usage for java.io UnsupportedEncodingException printStackTrace

List of usage examples for java.io UnsupportedEncodingException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

public static String getBase64(String str) {
    String result = "";
    if (str != null) {
        try {/*from w w  w .j a v  a2  s.c  o  m*/
            result = new String(Base64.encode(str.getBytes("utf-8"), Base64.NO_WRAP), "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    return result;
}

From source file:Main.java

public static String base64EncodingSenhaLogin(String user, String password) {

    String param = user + ":" + password;

    byte[] data = null;
    try {/*from  w  w w  . j  ava  2  s. co m*/
        data = param.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return Base64.encodeToString(data, Base64.DEFAULT).trim();
}

From source file:Main.java

public static String getContent(byte[] text, int offset) {
    if (text == null) {
        return null;
    }/*from w ww.j av  a 2 s  .  c om*/
    try {
        int len = text[offset];
        return new String(text, offset + 1, len, ENCODING);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static String base64decode(String base64) {
    String decoded = "";
    if (base64 != null) {
        try {//from  w  w  w  .  ja v a 2 s .c  o m
            decoded = new String(Base64.decode(base64, Base64.DEFAULT), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    return decoded;
}

From source file:Main.java

public static byte[] getBytes(String src, Charset charSet) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
        try {//  w  w  w. j  a v a2 s.c om
            return src.getBytes(charSet.name());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    } else {
        return src.getBytes(charSet);
    }
}

From source file:Main.java

private static String encode(String input) {
    if (input == null) {
        return "";
    }/*from w  w  w  . j  a  va 2s  . c  o  m*/

    try {
        return URLEncoder.encode(input, "utf-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return input;
}

From source file:Main.java

public static String recode(String str) {
    String formart = "";
    try {//from   w ww. java 2  s  .c o m
        boolean ISO = Charset.forName("ISO-8859-1").newEncoder().canEncode(str);
        if (ISO) {
            formart = new String(str.getBytes("ISO-8859-1"), "GB2312");
        } else {
            formart = str;
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return formart;
}

From source file:Main.java

public static String encodeingUrl(String url) {
    try {//from   w  w w. j  av a  2  s.  c  o  m
        return URLEncoder.encode(url, "utf-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return replaceSpace(url);

}

From source file:Main.java

public static int getTextLength(String str) {
    int length = 0;
    try {/*from  ww w . j  av a 2 s .  c o m*/
        str = new String(str.getBytes("GBK"), "ISO8859_1");
        length = str.length();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return length;
}

From source file:Main.java

public static String encodeUrl(String url) {
    String new_url = url;
    Matcher matcher = Pattern.compile("[\\u4e00-\\u9fa5]").matcher(new_url);
    while (matcher.find()) {
        try {//from w  ww. java  2 s . co  m
            new_url = new_url.replaceAll(matcher.group(), URLEncoder.encode(matcher.group(), "gb2312"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    return new_url;
}