List of usage examples for java.io UnsupportedEncodingException printStackTrace
public void printStackTrace()
From source file:Main.java
public static String decodeURL(String s, String charsetName) { if (s == null) { return null; }/*from w w w . j ava 2 s.c o m*/ try { if (TextUtils.isEmpty(charsetName)) { charsetName = Charset.defaultCharset().displayName(); } return URLDecoder.decode(s, charsetName); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String extract(String response, Pattern p) { Matcher matcher = p.matcher(response); if (matcher.find() && matcher.groupCount() >= 1) { try {/*from w w w. j a v a2s . c om*/ return URLDecoder.decode(matcher.group(1), UTF_8); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } throw new RuntimeException( "Response body is incorrect. Can't extract token and secret from this: '" + response + "'", null); }
From source file:Main.java
public static InputStream stringToInputStream(String str, String code) { if (TextUtils.isEmpty(code)) { return new ByteArrayInputStream(str.getBytes()); } else {//from w ww.j ava2 s. c om try { return new ByteArrayInputStream(str.getBytes(code)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return new ByteArrayInputStream(str.getBytes()); } } }
From source file:Main.java
public static byte[] string2Bytes(String s, String charsetName) { if (s == null) { return null; }/*w w w .j a v a 2s. c o m*/ if (charsetName == null) { return s.getBytes(); } else { try { return s.getBytes(charsetName); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } } }
From source file:Main.java
public static String encode(CharSequence target) { if (target == null) { return ""; }/* w w w .ja v a 2s . c o m*/ String result = target.toString(); try { result = URLEncoder.encode(result, "UTF8"); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } return result; }
From source file:Main.java
public static String generateBasicAuthToken(String name, String secret) { StringBuilder sb = new StringBuilder(); sb.append(name).append(":").append(secret); try {/*from www . ja v a 2 s .c o m*/ return AUTH_PREFIX_BASIC + Base64.encodeToString(sb.toString().getBytes("UTF-8"), Base64.URL_SAFE | Base64.NO_WRAP); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static byte[] conversionEncoding(byte[] text, String fromCharset, String newCharset) { try {//from w w w . ja v a 2 s. c om String str = new String(text, fromCharset); return str.getBytes(newCharset); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String changeSizeThumbURL(String url, final int sizeWidthOfItem) { if ((url == null) || url.equals("")) { return url; }//from w ww . ja va 2 s .com try { url = URLDecoder.decode(url, "UTF-8"); } catch (final UnsupportedEncodingException e) { e.printStackTrace(); } if (url.contains("/thumb_w/") && url.contains(",") && ((url.indexOf("/thumb_w/") + 5) < url.indexOf(","))) { final int size = (sizeWidthOfItem + 100) - (sizeWidthOfItem % 100); if ((size > 0) && (size < 1000) && ((size % 100) == 0)) { url = url.substring(0, url.indexOf("/thumb_w/")) + "/thumb_w/" + size + url.substring(url.indexOf(","), url.length()); } } return url; }
From source file:Main.java
public static String MD5(String md5) { try {//from w ww. j av a 2 s. co m java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); byte[] array; try { array = md.digest(md5.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); array = md.digest(md5.getBytes()); } StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; ++i) { sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); } return sb.toString(); } catch (java.security.NoSuchAlgorithmException e) { } return null; }
From source file:Main.java
static String map2UrlQueryString(Map<String, Object> map) { StringBuilder sb = new StringBuilder(); for (HashMap.Entry<String, Object> e : map.entrySet()) { try {/*from w w w . ja v a2 s . c o m*/ sb.append(e.getKey()); sb.append('='); sb.append(URLEncoder.encode(String.valueOf(e.getValue()), "UTF-8")); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } sb.append('&'); } if (sb.length() == 0) return ""; else return sb.substring(0, sb.length() - 1); }