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 Object parseXmlStringToBeanByJAXB(String xml, Class clase) throws Exception {

    JAXBContext context = JAXBContext.newInstance(clase);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    InputStream is = null;/* w ww.j  av a 2 s  .  co  m*/
    try {
        is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    if (is == null) {
        return null;
    }

    JAXBElement elm = unmarshaller.unmarshal(new StreamSource(is), clase);

    return elm.getValue();

}

From source file:Main.java

public static String prepareParameterizedGetUrl(String url, List<NameValuePair> params) {

    url += "?";//w w  w.ja  va2 s.  c  o m
    if (params != null) {
        for (NameValuePair pair : params) {
            try {
                url += pair.getName() + "=" + URLEncoder.encode(pair.getValue(), "UTF-8") + "&";
            } catch (UnsupportedEncodingException e) {

                e.printStackTrace();
                break;
            }

        }
        url = url.substring(0, url.trim().length() - 1);
    }
    return url;
}

From source file:Main.java

public static String unEscapeTemplatedURIComponent(String uri) {
    try {//from  ww  w.  j a  v a2 s. c  o m
        uri = URLDecoder.decode(uri, "utf-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    uri = restoreAll(uri, ":", "?");
    uri = restoreAll(uri, ":", "/");
    return uri;
}

From source file:Main.java

public static String getString(InputStream inputStream) {
    InputStreamReader inputStreamReader = null;
    try {//from  w  ww  . j  a  va2 s.  co  m
        inputStreamReader = new InputStreamReader(inputStream, "gbk");
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    }
    BufferedReader reader = new BufferedReader(inputStreamReader);
    StringBuffer sb = new StringBuffer("");
    String line;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line);
            sb.append("\n");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return sb.toString();
}

From source file:Main.java

private static Element getRootNodeFromXmlUrl(String xmlUrl) {
    Element element = null;//from   www .j a va  2 s  . c o  m
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document document = db.parse(xmlUrl);
        element = document.getDocumentElement();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return element;
}

From source file:com.revolucion.secretwit.stego.URLSteganography.java

public static String encode(String text) {
    try {// w  w w.  j ava2  s.  c om
        return new String(Base64.encodeBase64(text.getBytes(DEFAULT_CHARSET), false, true, 10));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:com.revolucion.secretwit.stego.URLSteganography.java

public static String decode(String text) {
    try {/*from  ww  w. j ava2  s  .com*/
        return new String(Base64.decodeBase64(text), DEFAULT_CHARSET);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:logic.core.file.FileSystemInit.java

public static void init() {
    try {//from  w w  w. ja va 2  s.c  o  m
        jarPathOnSystem = FilenameUtils.getPath(URLDecoder.decode(
                GameRunner.class.getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8"));

        String dataPath = jarPathOnSystem + "/data/";

        File temp = new File(dataPath);
        temp.mkdir();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static String encodeStr(String s) {
    String s1;/*from   ww w. j a  v  a 2s  .  c  o m*/
    try {
        s1 = URLEncoder.encode(s, "UTF-8");
    } catch (UnsupportedEncodingException unsupportedencodingexception) {
        unsupportedencodingexception.printStackTrace();
        return null;
    } catch (Exception exception) {
        exception.printStackTrace();
        return null;
    }
    return s1;
}

From source file:Main.java

public static String urlEncode(String stringToEncode) {
    String stringEncoded;// w  w  w  .j a  va  2s.  c o  m
    try {
        stringEncoded = URLEncoder.encode(stringToEncode, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        stringEncoded = null;
        e.printStackTrace();
    }
    return stringEncoded;
}