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:com.grandcircus.controller.GoogleGeocode.java

/**
 * Given the string of an address, return a Coordinates object that contains
 * the coordinate information extracted from the API response
 *
 * @param address the string representation of a physical address
 * @return Coordinates object containing coordinate information from response
 *///from   w ww.  j a  va2  s  .  c  o  m
public static Coordinates geocode(String address) {
    Coordinates coords = new Coordinates();

    String requestUrl = "";
    try {
        requestUrl = buildURL(address);
    } catch (UnsupportedEncodingException uee) {
        uee.printStackTrace();
    }

    GetMethod getMethod = new GetMethod(requestUrl);
    getMethod.setFollowRedirects(true);

    try {
        httpClient.executeMethod(getMethod);

        // build the response object
        GoogleGeocodeResponse response = new GoogleGeocodeResponse(
                IOUtils.toString(getMethod.getResponseBodyAsStream(), getMethod.getRequestCharSet()));
        /**
         * Parsing can be done via Dom Document as well:
         * GoogleGeocodeResponse response = new GoogleGeocodeResponse(getMethod.getResponseBodyAsStream());
         */

        // only change coordinates from default if request successful
        if (response.successful()) {
            coords = response.getCoords();
        }
    } catch (Exception e) {
        System.out.println("Geocode exception: " + e.toString());
    } finally {
        getMethod.abort();
        getMethod.releaseConnection();
    }

    return coords;
}

From source file:edu.clemson.lph.utils.Encodings.java

/**
 * Convert a String--normally XML--into Windows .Net format string (UTF-16 with Little Endian byte order)
 * encoded in base64 binary String format.  Used to populate base64Binary fields in .Net generated SOAP 
 * services.  Edit the WSDL prior to code generation to accept a string instead of a base64Binary type
 * because SOAP would generate that in UTF-8.
 * @param sXML//  w w w  .j a v a 2s  .co m
 * @return String in base64
 */
public static String getBase64Utf16Le(String sXML) {
    String sBase64 = null;
    byte[] bytes;
    try {
        bytes = sXML.getBytes("UTF-16LE"); // Tested, specifying little endian really is essential.
        byte[] base64Bytes = Base64.encodeBase64(bytes);
        sBase64 = new String(base64Bytes);
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return sBase64;
}

From source file:edu.clemson.lph.utils.Encodings.java

/**
 * Convert a String--normally XML--into normal base64Binary format string (UTF-8).
 * Used for most cases of base64 encoding of content to include in SOAP or other XML 
 * content./*from  ww  w  . ja  v a  2s.  co  m*/
 * @param sXML
 * @return String in base64
 */
public static String getBase64Utf8(String sXML) {
    String sBase64 = null;
    byte[] bytes;
    try {
        bytes = sXML.getBytes("UTF-8");
        byte[] base64Bytes = Base64.encodeBase64(bytes);
        sBase64 = new String(base64Bytes);
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return sBase64;
}

From source file:net.a2bsoft.buss.http.SendQuery.java

public static String sendQuery(String query) {

    try {/*from  w ww .  j a  v  a  2s .com*/
        query = URLEncoder.encode(query, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return e.getMessage();
    }
    URL url = null;
    try {
        url = new URL(
                "http://www.atb.no/xmlhttprequest.php?service=routeplannerOracle.getOracleAnswer&question="
                        + query);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    String result = null;
    HttpParams my_httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(my_httpParams, 30000);
    HttpConnectionParams.setSoTimeout(my_httpParams, 30000);
    HttpClient client = new DefaultHttpClient(my_httpParams);
    HttpGet get = new HttpGet(url.toString());
    HttpResponse resp;

    try {
        resp = client.execute(get);
        InputStream data = resp.getEntity().getContent();
        result = new BufferedReader(new InputStreamReader(data)).readLine();

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return sendQueryBusstuc(query);
        //         return e.getMessage();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return sendQueryBusstuc(query);
        //         return e.getMessage();
    }

    return result;
}

From source file:com.msbmsb.gogogeocode.GoGoGeocode.java

/**
 * Given the string of an address, return a Coordinates object that contains
 * the coordinate information extracted from the API response
 * @param address the string representation of a physical address
 * @return Coordinates object containing coordinate information from response
 *///from   w  w w .  j  av a2 s .c o  m
public static Coordinates geocode(String address) {
    Coordinates coords = new Coordinates();

    String requestUrl = "";
    try {
        requestUrl = buildURL(address);
    } catch (UnsupportedEncodingException uee) {
        uee.printStackTrace();
    }

    GetMethod getMethod = new GetMethod(requestUrl);
    getMethod.setFollowRedirects(true);

    try {
        httpClient.executeMethod(getMethod);

        // build the response object
        GoogleGeocodeResponse response = new GoogleGeocodeResponse(
                IOUtils.toString(getMethod.getResponseBodyAsStream(), getMethod.getRequestCharSet()));
        /**
         * Parsing can be done via Dom Document as well: 
         * GoogleGeocodeResponse response = new GoogleGeocodeResponse(getMethod.getResponseBodyAsStream());
         */

        // only change coordinates from default if request successful
        if (response.successful()) {
            coords = response.getCoords();
        }
    } catch (Exception e) {
        System.out.println("Geocode exception: " + e.toString());
    } finally {
        getMethod.abort();
        getMethod.releaseConnection();
    }

    return coords;
}

From source file:com.aqnote.shared.cryptology.digest.MD.java

public final static String md2(String src) {
    if (isBlank(src))
        return "";
    try {//from   w  ww .j a  v  a  2s.  c  o m
        return md2(src.getBytes(DEFAULT_CHARSET));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:com.aqnote.shared.cryptology.digest.MD.java

public final static String md4(String src) {
    if (isBlank(src))
        return "";
    try {/*  ww w.java2s  .co m*/
        return md4(src.getBytes(DEFAULT_CHARSET));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:com.aqnote.shared.cryptology.digest.MD.java

public final static String md5(String src) {
    if (isBlank(src))
        return "";
    try {//w  w  w. j ava 2s  .c o m
        return md5(src.getBytes(DEFAULT_CHARSET));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:cn.org.citycloud.srdz.utils.StringUtils.java

/**
 * ?/*from  w w w  . j  ava2 s .co  m*/
 * @param str 
 * @param length ?
 * @return
 */
public static String abbr(String str, int length) {
    if (str == null) {
        return "";
    }
    try {
        StringBuilder sb = new StringBuilder();
        int currentLength = 0;
        for (char c : replaceHtml(StringEscapeUtils.unescapeHtml4(str)).toCharArray()) {
            currentLength += String.valueOf(c).getBytes("GBK").length;
            if (currentLength <= length - 3) {
                sb.append(c);
            } else {
                sb.append("...");
                break;
            }
        }
        return sb.toString();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static String mergeFlockedFiles(String FilePath) {

    String result = null;//ww w  .  j  a  v a 2 s.  c o  m
    try {
        result = java.net.URLDecoder.decode(FilePath, "UTF-8");
    } catch (UnsupportedEncodingException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    String fileName = result.substring(result.lastIndexOf('/') + 1);
    if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {

        File flockedFilesFolder = new File(
                Environment.getExternalStorageDirectory() + File.separator + "FlockLoad");
        System.out.println("FlockedFileDir: " + flockedFilesFolder);
        long leninfile = 0, leng = 0;
        int count = 1, data = 0;
        int bytesRead = 0;
        try {
            File filename = new File(flockedFilesFolder.toString() + "/" + fileName);
            if (filename.exists())
                filename.delete();
            //BUFFER_SIZE = (int) filename.length();
            System.out.println("filename: " + filename);
            FileOutputStream fos = new FileOutputStream(filename, true);

            while (true) {
                File filepart = new File(filename + ".part" + count);
                System.out.println("part filename: " + filepart);
                if (filepart.exists()) {
                    FileInputStream fis = new FileInputStream(filepart);
                    byte fileBytes[] = new byte[(int) filepart.length()];
                    bytesRead = fis.read(fileBytes, 0, (int) filepart.length());
                    assert (bytesRead == fileBytes.length);
                    assert (bytesRead == (int) filepart.length());
                    fos.write(fileBytes);
                    fos.flush();
                    fileBytes = null;
                    fis.close();
                    fis = null;
                    count++;
                    filepart.delete();
                } else
                    break;
            }
            fos.close();
            fos = null;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return fileName;
}