List of usage examples for java.io UnsupportedEncodingException printStackTrace
public void printStackTrace()
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 .j a v a 2 s. c o m if (dirs.length > 1) { for (int i = 0; i < dirs.length - 1; i++) { substr = dirs[i]; try { substr = new String(substr.getBytes("8859_1"), "GB2312"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } ret = new File(ret, substr); } Log.d(TAG, "1ret = " + ret); if (!ret.exists()) ret.mkdirs(); substr = dirs[dirs.length - 1]; try { substr = new String(substr.getBytes("8859_1"), "GB2312"); Log.d(TAG, "substr = " + substr); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } ret = new File(ret, substr); Log.d(TAG, "2ret = " + ret); return ret; } // a single file name without relatvie path, try { substr = new String(absFileName.getBytes("8859_1"), "GB2312"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } ret = new File(ret, substr); return ret; }
From source file:Main.java
public static boolean getkeepaliveinfo() { String baseUrl = "http://10.6.8.2/cgi-bin/keeplive?"; try {/*from ww w .j a va2s. c o m*/ HttpGet getMethod = new HttpGet(baseUrl); getMethod.addHeader("Accept", "*/*"); //getMethod.addHeader("Accept-Language", "zh-cn"); //getMethod.addHeader("Referer", "http://202.117.2.41/index.html"); //getMethod.addHeader("Content-Type", "application/x-www-form-urlencoded"); //getMethod.addHeader("Accept-Encoding", "gzip, deflate"); //getMethod.addHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)"); getMethod.addHeader("Host", "10.6.8.2"); //getMethod.addHeader("DNT", "1"); HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(getMethod); Log.i(TAG, "Sending message....."); HttpEntity httpEntity = response.getEntity(); if (response.getStatusLine().getStatusCode() == 200) { String message = EntityUtils.toString(httpEntity); if (httpEntity == null || message.compareTo("error") == 0) { Log.i(TAG, "Get keepalive info failed!!!message=" + message); return false; } else { Log.i(TAG, "Get keepalive info succeed!!!message=" + message); return true; } } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.i(TAG, "Get keepalive info failed!!!"); return false; }
From source file:Main.java
public static String byteToString(byte[] data) { int index = data.length; for (int i = 0; i < data.length; i++) { if (data[i] == 0) { index = i;/*w ww . ja v a 2 s . com*/ break; } } byte[] temp = new byte[index]; Arrays.fill(temp, (byte) 0); System.arraycopy(data, 0, temp, 0, index); String str; try { str = new String(temp, "GBK"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } return str; }
From source file:Main.java
public static String urlencode(Map<String, ?> data) { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, ?> i : data.entrySet()) { try {/* www . j av a 2 s . com*/ sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue() + "", "UTF-8")).append("&"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return sb.toString(); }
From source file:Main.java
public static String buildString(Map<String, String> params) { if (params == null || params.size() == 0) return null; StringBuilder sb = new StringBuilder(); Set<Entry<String, String>> setEntry = params.entrySet(); for (Entry<String, String> entry : setEntry) { sb.append(entry.getKey());/*from w ww. j a v a 2 s . co m*/ sb.append("="); try { sb.append(getUrlEncode(entry.getValue(), "utf-8") + "&"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } sb.deleteCharAt(sb.length() - 1); return sb.toString(); }
From source file:Main.java
public static String enThunder(String url) { url = "AA" + url + "ZZ"; try {/*from ww w . ja v a 2s. c o m*/ byte[] bytes = url.getBytes("GBK"); String temp = "" + new String(Base64.encode(bytes, Base64.DEFAULT)); url = ""; char[] base64EncodeChars = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '=' }; for (int i = 0; i < temp.length(); i++) for (int j = 0; j < base64EncodeChars.length; j++) { if ((int) temp.charAt(i) == (int) base64EncodeChars[j]) { url = url + temp.charAt(i); break; } } url = "thunder://" + url; // System.out.println(key); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return url; }
From source file:Main.java
public static String findValueInUrl(String url, String key) { String[] params = url.split("&"); String value = ""; for (String p : params) { if (p.contains(key)) { try { value = URLDecoder.decode(p.split("=")[1], "utf-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); }//from ww w .j ava2 s. c o m } } return value; }
From source file:Main.java
public static String buildEncodedQueryString(HashMap<String, String> requestParams) { String queryString = "?"; if (requestParams == null) { return null; }//from ww w .j a va 2 s . c o m Iterator<Entry<String, String>> it = requestParams.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> pairs = (Map.Entry<String, String>) it.next(); try { queryString += URLEncoder.encode(pairs.getKey().toString(), "UTF-8") + "=" + URLEncoder.encode(pairs.getValue().toString(), "UTF-8") + "&"; } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (queryString.length() > 0) queryString = queryString.substring(0, queryString.length() - 1); return queryString; }
From source file:Main.java
public static String getStringFromFile(String pathUrlName, boolean encode) { Writer writer = null;//w ww. j a v a 2 s .c o m try { InputStream is = new FileInputStream(new File(pathUrlName)); writer = new StringWriter(); char[] buffer = new char[1024]; try { Reader reader; if (encode) { reader = new BufferedReader(new InputStreamReader(is, HTML_ENCODING)); } else { reader = new BufferedReader(new InputStreamReader(is)); } int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } finally { is.close(); } } catch (IOException e) { e.printStackTrace(); } return writer.toString(); }
From source file:com.android.isoma.enc.ServerCommunicator.java
public static String executePost(ArrayList<NameValuePair> postParameters) { String ServerResponse = null; HttpClient httpClient = getHttpClient(); ResponseHandler<String> response = new BasicResponseHandler(); HttpPost request = new HttpPost(url); try {//from www.j av a 2 s. com request.setHeader("Content-Type", "application/x-www-form-urlencoded"); request.setEntity(new UrlEncodedFormEntity(postParameters, HTTP.UTF_8)); ServerResponse = httpClient.execute(request, response); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ServerResponse; }