List of usage examples for java.io UnsupportedEncodingException printStackTrace
public void printStackTrace()
From source file:Main.java
public static String openPostConnection(String urlString, Map<String, String> map) { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(urlString); List<NameValuePair> nameValuePairs = new ArrayList<>(); for (String key : map.keySet()) { nameValuePairs.add(new BasicNameValuePair(key, map.get(key))); }//www .ja va 2 s . c o m try { post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } try { HttpResponse httpResponse = client.execute(post); BufferedReader br = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent())); StringBuilder json = new StringBuilder(""); String line = null; while ((line = br.readLine()) != null) { json.append(line); } return json.toString(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static byte[] decode(String str) { try {/* w w w. java 2 s .co m*/ byte[] decodeStr = decodePrivate(str); return decodeStr; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return new byte[] {}; }
From source file:com.github.breadmoirai.samurai.util.SearchResult.java
public static SearchResult fromGoogle(JSONObject googleResult) { SearchResult result = new SearchResult(); result.title = cleanString(googleResult.getString("title")); result.content = cleanString(googleResult.getString("snippet")); try {/*from w w w. ja va2 s .c om*/ result.url = URLDecoder.decode(cleanString(googleResult.getString("link")), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return result; }
From source file:Main.java
public static String urlEncode(String msg) { if (TextUtils.isEmpty(msg)) { return null; }/*from w ww .j a v a 2 s .c om*/ try { return URLEncoder.encode(msg, "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:Main.java
public static HttpEntity buildUrlEncodedFormEntity(Map<String, String> keyValuePairs) { List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); if (keyValuePairs != null) { Set<String> keys = keyValuePairs.keySet(); for (String key : keys) { String value = keyValuePairs.get(key); BasicNameValuePair param = new BasicNameValuePair(key, value); params.add(param);/*from w w w . j a v a 2 s .c o m*/ } } try { return new UrlEncodedFormEntity(params); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:Main.java
private static String getStringFromException(Throwable e) { String result = ""; ByteArrayOutputStream bos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(bos); e.printStackTrace(ps);// ww w . j a va2 s.com try { result = bos.toString("utf-8"); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return result; }
From source file:Main.java
static public boolean isCN(String str) { try {/* ww w. ja v a2 s . com*/ byte[] bytes = str.getBytes("UTF-8"); if (bytes.length == str.length()) { return false; } else { return true; } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; }
From source file:com.snowplowanalytics.snowplow.tracker.core.Util.java
public static String base64Encode(String string) { try {// w w w .ja va2 s .c om return Base64.encode(string.getBytes()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:com.aistor.common.utils.StringUtils.java
/** * ?/*from ww w. j av a 2s .c o 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 : 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 getDecoder(String str) { try {/* w ww.j a v a2 s . c o m*/ return URLDecoder.decode(str, "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }