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:org.guohai.android.cta.utility.HttpRest.java

/**
 * HTTPPost?/* ww  w  . j  av a  2s .  co  m*/
 * @param url POST?
 * @param pairs ?
 * @return ?JOSN?null
 */
public static ResultInfo HttpPostClient(String url, List<NameValuePair> pairs) {
    //create http client
    HttpClient client = new DefaultHttpClient();
    //create post request
    HttpPost httpPost = new HttpPost(url);
    //return value
    ResultInfo result = new ResultInfo();
    //init eroor value
    result.State = -1000;
    result.Message = "posterror";

    HttpEntity entity;
    try {
        entity = new UrlEncodedFormEntity(pairs, HTTP.UTF_8);

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Log.e(TAG, e.getMessage());
        return result;
    }
    httpPost.setEntity(entity);

    //??POST? 
    try {
        HttpResponse response = client.execute(httpPost);
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entityHtml = response.getEntity();
            BufferedReader reader = new BufferedReader(new InputStreamReader(entityHtml.getContent(), "UTF-8"));
            String line = null;
            String reString = "";
            while ((line = reader.readLine()) != null) {
                reString += line;
            }
            if (entityHtml != null) {
                entityHtml.consumeContent();
            }
            Log.i(TAG, reString);
            JSONObject jsonObj;

            try {
                jsonObj = new JSONObject(reString);
                result.State = jsonObj.getInt("state");
                result.Message = jsonObj.getString("message");
                return result;
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Log.e(TAG, e.getMessage());
            } catch (NumberFormatException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Log.e(TAG, e.getMessage());
            }
            return result;
        }
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Log.e(TAG, e.getMessage());

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Log.e(TAG, e.getMessage());
    }
    return result;
}

From source file:net.openwatch.acluaz.http.OWServiceRequests.java

public static StringEntity jsonToSE(JSONObject json) {
    StringEntity se = null;/*from  w  w  w. j a  va 2  s  .  co m*/
    try {
        se = new StringEntity(json.toString());
        Log.i(TAG, "reportToJSON: " + json.toString());
        return se;
    } catch (UnsupportedEncodingException e1) {
        Log.e(TAG, "json->stringentity failed");
        e1.printStackTrace();
    }

    return se;
}

From source file:com.log4ic.compressor.utils.FileUtils.java

/**
 * //from  ww  w.j  a  va  2  s  . com
 *
 * @param content
 * @param filePath
 * @return
 */
public static File writeFile(String content, String filePath) {
    byte[] contentByte = new byte[0];
    if (StringUtils.isNotBlank(content)) {
        try {
            contentByte = content.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    return writeFile(contentByte, filePath);
}

From source file:co.mitro.twofactor.CryptoForBackupCodes.java

public static byte[] encodedStringToBytes(String saltCode) {
    byte[] toBytes = null;
    byte[] bytes = null;
    try {//  ww  w .java2 s.c  o  m
        bytes = saltCode.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    toBytes = Base64.decodeBase64(bytes);

    return toBytes;
}

From source file:com.ms.commons.utilities.CharTools.java

/**
 * strUTF8?<br>//from www.j  a v  a  2  s. c  om
 * ??oracle?UTF??
 * 
 * @param str
 * @return
 */
public static long getLength4UTF8(String str) {
    if (str == null || str.length() == 0) {
        return 0;
    }
    char[] chars = str.toCharArray();
    long length = 0;
    for (int i = 0; i < chars.length; i++) {
        byte[] bytes;
        try {
            bytes = ("" + chars[i]).getBytes("UTF-8");
            length += bytes.length;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    return length;
}

From source file:gov.llnl.ontology.mapreduce.table.SchemaUtil.java

/**
 * Returns the text for a given column./*from  w  w w .  java2 s. c  o m*/
 */
public static String getColumn(Result row, String family, String qualifier) {
    try {
        // Get the raw text
        byte[] bytes = row.getValue(family.getBytes(), qualifier.getBytes());
        if (bytes == null)
            return null;
        String text = new String(bytes, HConstants.UTF8_ENCODING);
        return text;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}

From source file:net.shopxx.util.CookieUtils.java

/**
 * ?cookie/*www .  j  a  v  a 2  s.c  o m*/
 * 
 * @param request
 *            HttpServletRequest
 * @param name
 *            cookie??
 * @return ?null
 */
public static String getCookie(HttpServletRequest request, String name) {
    Assert.notNull(request);
    Assert.hasText(name);
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        try {
            for (Cookie cookie : cookies) {
                if (name.equals(cookie.getName())) {
                    return URLDecoder.decode(cookie.getValue(), "UTF-8");
                }
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    return null;
}

From source file:language_engine.bing.BingTranslationApi.java

private static String generateUrl(String accessToken, List<String> querys, SupportedLanguages from,
        SupportedLanguages to) {//  w  ww .ja va2 s .c om
    String[] texts = new String[] {};
    texts = querys.toArray(texts);
    for (int i = 0; i < texts.length; i++) {
        texts[i] = StringEscapeUtils.escapeJava(texts[i]);
    }

    try {
        final String params = (accessToken != null
                ? PARAM_APP_ID + URLEncoder.encode("Bearer " + accessToken, ENCODING)
                : "") + PARAM_FROM_LANG + URLEncoder.encode(from.getLanguageCode(), ENCODING) + PARAM_TO_LANG
                + URLEncoder.encode(to.getLanguageCode(), ENCODING) + PARAM_TEXT_ARRAY
                + URLEncoder.encode(buildStringArrayParam(texts), ENCODING);

        return TRANSLATE_URL + params;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:example.DecrypterException.java

public static String decryptSafeWebString(String webString, String secretKey, String signKey) {
    byte[] bytes = decryptSafeWebStringToByte(webString, secretKey, signKey);
    String retStr = null;// ww w  . ja  v a2s .c  o  m
    try {
        retStr = new String(bytes, "utf-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return retStr;
}

From source file:net.shopxx.util.CookieUtils.java

/**
 * cookie//  www. j  a va 2 s.  c  o  m
 * 
 * @param request
 *            HttpServletRequest
 * @param response
 *            HttpServletResponse
 * @param name
 *            cookie??
 * @param value
 *            cookie
 * @param path
 *            
 * @param maxAge
 *            (??: )
 * @param domain
 *            
 * @param secure
 *            ??
 */
public static void addCookie(HttpServletRequest request, HttpServletResponse response, String name,
        String value, String path, Integer maxAge, String domain, Boolean secure) {
    Assert.notNull(request);
    Assert.notNull(response);
    Assert.hasText(name);
    try {
        value = URLEncoder.encode(value, "UTF-8");
        Cookie cookie = new Cookie(name, value);
        if (StringUtils.isNotEmpty(path)) {
            cookie.setPath(path);
        }
        if (maxAge != null) {
            cookie.setMaxAge(maxAge);
        }
        if (StringUtils.isNotEmpty(domain)) {
            cookie.setDomain(domain);
        }
        if (secure != null) {
            cookie.setSecure(secure);
        }
        response.addCookie(cookie);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}