List of usage examples for java.io UnsupportedEncodingException printStackTrace
public void printStackTrace()
From source file:com.aliyun.android.oss.http.OSSHttpTool.java
public static String encodeUri(String uri) { StringBuffer encodeBuffer = new StringBuffer(); String[] splitArray = uri.split("/"); for (String part : splitArray) { try {// w w w . jav a 2 s . c o m encodeBuffer.append(URLEncoder.encode(part, "UTF-8")).append("/"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } if (!uri.endsWith("/")) { encodeBuffer.deleteCharAt(encodeBuffer.length() - 1); } return encodeBuffer.toString(); }
From source file:com.bluetooth.activities.WiFiControl.java
/** * This function converts an InputStream in a String, this is needed to * serve the .htm file to the client.// www. ja va2 s . co m * <p> * To convert the InputStream to String we use the Reader.read(char[] * buffer) method. We iterate until the Reader return -1 which means there's * no more data to read. We use the StringWriter class to produce the * string. */ protected static String openHTMLString(Context context, int id) { InputStream is = context.getResources().openRawResource(id); if (is != null) { Writer writer = new StringWriter(); char[] buffer = new char[1024]; try { Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return writer.toString(); } else { return ""; } }
From source file:gov.in.bloomington.georeporter.models.Open311.java
/** * POST new service request data to the endpoint * /*from w ww . j a v a 2 s . co m*/ * @param data * @return * JSONObject */ public static JSONArray postServiceRequest(List<NameValuePair> data) { HttpPost post = new HttpPost(mBaseUrl + "/requests.json"); JSONArray response = new JSONArray(); try { post.setEntity(new UrlEncodedFormEntity(data)); HttpResponse r = mClient.execute(post); response = new JSONArray(EntityUtils.toString(r.getEntity())); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return response; }
From source file:org.bfr.querytools.spectrumbridge.SpectrumBridgeQuery.java
public static void query(double latitude, double longitude, boolean register) { Logger.log(String.format(Locale.US, "spectrumbridge-query-execute %.4f %.4f", latitude, longitude)); HttpResponse response = null;//from ww w . jav a 2 s . com SbiReturnCode returnCode; try { // Register if (register) { Logger.log("spectrumbridge-query registering"); response = register(antennaHeight, latitude, longitude); returnCode = sbiReturnCode(response); Logger.log("spectrumbridge-query registration: " + returnCode); if (returnCode != SbiReturnCode.Succes || returnCode == SbiReturnCode.GenericError) { Logger.log("spectrumbridge-query-error Registration Query Returned: " + returnCode); } else { readResponseBody(response); } } else Logger.log("spectrumbridge-query skipping registration"); // Query channel list Logger.log("spectrumbridge-query querying channel list"); response = channelQuery(latitude, longitude); returnCode = sbiReturnCode(response); Logger.log("spectrumbridge-query channel list: " + returnCode); if (returnCode != SbiReturnCode.Succes) { Logger.log("spectrumbridge-query-error Channel Query Returned: " + returnCode); } else { readResponseBody(response); } } catch (UnsupportedEncodingException e) { Logger.log("spectrumbridge-query-error Unsupported Encoding: " + e.getMessage()); } catch (IOException e) { e.printStackTrace(); Logger.log("spectrumbridge-query-error i/o exception: " + e.getMessage()); } Logger.log("spectrumbridge-query-done"); }
From source file:com.board.games.handler.discuz.DiscuzPokerLoginServiceImpl.java
private static synchronized String getMD5(String input) { try {//from w w w .jav a2 s.c o m MessageDigest md = MessageDigest.getInstance("MD5"); byte[] messageDigest = md.digest(input.getBytes("UTF-8")); BigInteger number = new BigInteger(1, messageDigest); String hashtext = number.toString(16); // Now we need to zero pad it if you actually want the full 32 // chars. while (hashtext.length() < 32) { hashtext = "0" + hashtext; } return hashtext; } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } return null; }
From source file:com.easyway.java.rpc.secure.security.Encodes.java
public static String encode(String str) { // Base64?, URL(Base64URL?'+''/''-''_' try {//from ww w.j a v a 2 s.c o m str = new String(Base64.encodeBase64(str.getBytes("GBK"), false, true)); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } StringBuffer buff1 = new StringBuffer(); // ? int length = list.size(); // ? ?? ? for (char c : str.toCharArray()) { // ? int i = list.indexOf(c); // ? list ??? ?? if (i < 0) { if (c == '-') { buff1.append("+"); } else if (c == '_') { buff1.append("/"); } else { buff1.append(c); } continue; } // ? i = i + offset < length ? i + offset : i + offset - length; buff1.append(list.get(i)); } return buff1.toString(); }
From source file:riddimon.android.asianetautologin.HttpUtils.java
public static String readStreamIntoString(InputStream in) { StringBuilder builder = new StringBuilder(); int buf_size = 50 * 1024; // read in chunks of 50 KB ByteArrayBuffer bab = new ByteArrayBuffer(buf_size); int read = 0; BufferedInputStream bis = new BufferedInputStream(in); if (bis != null) { byte buffer[] = new byte[buf_size]; try {/*ww w .j av a 2 s . c o m*/ while ((read = bis.read(buffer, 0, buf_size)) != -1) { //builder.append(new String(buffer, "utf-8")); bab.append(buffer, 0, read); } builder.append(new String(bab.toByteArray(), "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { bis.close(); } catch (IOException e) { e.printStackTrace(); } } } return builder.toString(); }
From source file:riddimon.android.asianetautologin.HttpUtils.java
private static String getEncodedParameters(Map<String, String> params) { StringBuilder s = new StringBuilder(); synchronized (params) { for (String key : params.keySet()) { if (s.length() != 0) { s.append("&"); }// w w w . ja va 2 s .c om String value = params.get(key).toString(); String encodedValue = null; try { encodedValue = URLEncoder.encode(value, "utf8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); logger.warn("Could not encode URL"); } if (!TextUtils.isEmpty(encodedValue)) { s.append(key).append("=").append(encodedValue); } //logger.trace("Encoding from: {}", value); //logger.trace("Encoding to : {}", encodedValue); } } return s.toString(); }
From source file:com.denimgroup.threadfix.remote.HttpRestUtils.java
public static String encode(String input) { try {//from w w w. j ava2 s. c om return URLEncoder.encode(input, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } }
From source file:net.opentracker.android.OTSend.java
/** * Sends the key value pairs to Opentracker's logging/ analytics engines via * HTTP POST requests.//from w ww .j a v a 2 s. c o m * * Based on sending key value pairs documentated at: * http://api.opentracker.net/api/inserts/insert_event.jsp * * @param keyValuePairs * the key value pairs (plain text utf-8 strings) to send to the * logging service. * * @return the response as string, null if an exception is caught */ protected static String send(HashMap<String, String> keyValuePairs) { LogWrapper.v(TAG, "send(HashMap<String, String> keyValuePairs)"); // http://www.wikihow.com/Execute-HTTP-POST-Requests-in-Android // http://hc.apache.org/httpclient-3.x/tutorial.html HttpClient client = new DefaultHttpClient(); // time to wait before throwing timeout exception client.getParams().setParameter("http.socket.timeout", new Integer(HTTP_SOCKET_TIMEOUT)); HttpPost post = new HttpPost(DEFAULT_LOG_URL); post.getParams().setParameter("http.socket.timeout", new Integer(HTTP_SOCKET_TIMEOUT)); Iterator<Entry<String, String>> it = keyValuePairs.entrySet().iterator(); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); while (it.hasNext()) { Map.Entry<String, String> pair = (Map.Entry<String, String>) it.next(); pairs.add(new BasicNameValuePair(pair.getKey(), pair.getValue())); if (pair.getKey().equals("ots") || pair.getKey().equals("otui")) LogWrapper.v(TAG, pair.getKey() + " = " + pair.getValue()); else LogWrapper.v(TAG, pair.getKey() + " = " + pair.getValue()); } String responseText = null; try { post.setEntity(new UrlEncodedFormEntity(pairs)); HttpResponse response = client.execute(post); HttpEntity entity = response.getEntity(); // http://hc.apache.org/httpclient-3.x/tutorial.html // It is vital that the response body is always read regardless of // the status returned by the server. responseText = getResponseBody(entity); LogWrapper.v(TAG, "Success url:" + post.getURI()); LogWrapper.v(TAG, "Success url:" + pairs); return responseText; } catch (UnsupportedEncodingException e) { e.printStackTrace(); LogWrapper.w(TAG, "Failed:" + e); } catch (UnknownHostException e) { e.printStackTrace(); LogWrapper.w(TAG, "Failed:" + e); } catch (IOException e) { e.printStackTrace(); LogWrapper.w(TAG, "Failed:" + e); } catch (ParseException e) { e.printStackTrace(); LogWrapper.w(TAG, "Failed:" + e); } LogWrapper.e(TAG, "Got response " + responseText); return responseText; }