List of usage examples for java.io UnsupportedEncodingException printStackTrace
public void printStackTrace()
From source file:Main.java
public static String encodeUnicodeString(String source) { try {//from ww w . j a va 2 s.c o m source = URLEncoder.encode(source, "UTF-8"); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); } return source; }
From source file:Main.java
public static File getRealFileName(String baseDir, String absFileName) { String[] dirs = absFileName.split("/"); File ret = new File(baseDir); String substr = null;/*from w w w . ja va2 s. c o m*/ if (dirs.length > 1) { for (int i = 0; i < dirs.length - 1; i++) { substr = dirs[i]; try { // substr.trim(); substr = new String(substr.getBytes("8859_1"), "GB2312"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } ret = new File(ret, substr); } if (!ret.exists()) ret.mkdirs(); substr = dirs[dirs.length - 1]; // try { substr.trim(); ret = new File(ret, substr); return ret; } return ret; }
From source file:Main.java
private static int getBytesLength(String msg) { try {/*from w ww. j a va 2s .c o m*/ return msg.getBytes("GB2312").length; } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return 0; }
From source file:Main.java
private static int compareToGBK(String s1, String s2) { int ret = 0;/*from w ww. j av a 2 s . c om*/ try { byte[] bytes1 = s1.getBytes("gbk"); byte[] bytes2 = s2.getBytes("gbk"); int len = Math.min(bytes1.length, bytes2.length); for (int i = 0; i < len; i++) { if (bytes1[i] > 0 && bytes2[i] > 0) { ret = Character.toLowerCase(bytes1[i]) - Character.toLowerCase(bytes2[i]); if (ret == 0) ret = bytes1[i] - bytes2[i]; } else { int b1 = (bytes1[i] + 256) % 256; int b2 = (bytes2[i] + 256) % 256; ret = b1 - b2; } if (ret != 0) { break; } } if (ret == 0) { ret = bytes1.length - bytes2.length; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return ret; }
From source file:Main.java
public static String getDecodeString(String str) { java.net.URLDecoder ud = new URLDecoder(); try {// w w w. j a v a 2s.c o m str = ud.decode(str, "utf-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return str; }
From source file:Main.java
/** * Convert %XX// w ww .j ava 2s . co m * * @param value * @return */ public static String formParamDecode(String value) { int nCount = 0; for (int i = 0; i < value.length(); i++) { if (value.charAt(i) == '%') { i += 2; } nCount++; } byte[] sb = new byte[nCount]; for (int i = 0, index = 0; i < value.length(); i++) { if (value.charAt(i) != '%') { sb[index++] = (byte) value.charAt(i); } else { StringBuilder sChar = new StringBuilder(); sChar.append(value.charAt(i + 1)); sChar.append(value.charAt(i + 2)); sb[index++] = Integer.valueOf(sChar.toString(), 16).byteValue(); i += 2; } } String decode = ""; try { decode = new String(sb, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return decode; }
From source file:Main.java
public static byte[] stringToByte(String str) { byte[] s2byte = null; try {//w ww.j a va 2 s . c om s2byte = str.getBytes("GB2312"); } catch (UnsupportedEncodingException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } return s2byte; }
From source file:Main.java
public static String byteArrayOutStreamToString(ByteArrayOutputStream outputStream) { byte[] buf = outputStream.toByteArray(); try {/*from ww w . ja va2 s . co m*/ return new String(buf, "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } }
From source file:Main.java
public static byte[] decode(String str) { try {/*www. j a v a 2s . co m*/ return decodePrivate(str); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return new byte[] {}; }
From source file:Main.java
/** * Parse an entry name from a header buffer. * * @param header The header buffer from which to parse. * @param offset The offset into the buffer from which to parse. * @param length The number of header bytes to parse. * @return The header's entry name./* w w w . j av a 2s . c o m*/ */ public static StringBuffer parseName(byte[] header, int offset, int length) { StringBuffer result = null; int nameLen = length; int end = offset + length; for (int i = offset; i < end; ++i) { if (header[i] == 0) { nameLen = i - offset; break; } // result.append((char) header[i]); } try { result = new StringBuffer(new String(header, offset, nameLen, NAME_ENCODING)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return result; }