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 htmlDecode(String s) {
    if (s == null) {
        return null;
    }//from  w w  w  . j ava2 s .c om
    try {
        s = URLDecoder.decode(s, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return s;
}

From source file:Main.java

public static String dataToString(byte[] data, String charsetName) {
    if (data != null) {
        try {//from w  w  w . j  av a2  s .c  o m
            return new String(data, charsetName);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    return null;
}

From source file:Main.java

public static byte[] stringToData(String string, String charsetName) {
    if (string != null) {
        try {//from   ww w .j a v  a2s. c  om
            return string.getBytes(charsetName);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    return null;
}

From source file:Main.java

private static String setParams(String msg) {
    String url = "";
    try {/*  ww w.  ja v a  2s.  co m*/
        url = URL + "?key=" + API_KEY + "&info=" + URLEncoder.encode(msg, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return url;
}

From source file:Main.java

public static String base64Encode(String s) {
    byte[] data = new byte[0];
    try {/*from  w ww  .  j a  v a 2  s.co m*/
        data = s.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } finally {
        return Base64.encodeToString(data, Base64.NO_WRAP);
    }
}

From source file:Main.java

public static String encodeString(String str) {
    if (str == null) {
        return null;
    }/*from w w  w .j  ava2s  .  c  o  m*/
    try {
        str = URLEncoder.encode(str, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return str;
}

From source file:Main.java

public static String convertBase64(String str) {
    byte[] data;/*w w  w.  jav  a2  s  .com*/
    try {
        data = str.getBytes("UTF-8");
        String base64 = Base64.encodeToString(data, Base64.DEFAULT);
        return base64.trim();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static String base64Decode(String s) {
    byte[] dataDec = Base64.decode(s, Base64.NO_WRAP);
    String decodedString = "";
    try {/*from  w  w  w.  j  av a2 s. co  m*/
        decodedString = new String(dataDec, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } finally {
        return decodedString;
    }
}

From source file:Main.java

public static byte[] getBytes(String str) {
    if (str == null) {
        str = "";
    }//from  w  w  w  .  ja  v a  2 s  .  c  o m
    try {
        return str.getBytes(ENCODING);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String getFromBase64(String str) {
    String result = "";
    if (str != null) {
        try {//from   ww w .j a v  a  2  s . co m
            result = new String(Base64.decode(str, Base64.NO_WRAP), "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    return result;
}