List of usage examples for java.io UnsupportedEncodingException printStackTrace
public void printStackTrace()
From source file:org.opendatakit.utils.WebUtils.java
private static String readResponseHelper(InputStream content) { StringBuffer response = new StringBuffer(); if (content != null) { // TODO: this section of code is possibly causing 'WARNING: Going to // buffer // response body of large or unknown size. Using getResponseBodyAsStream // instead is recommended.' // The WARNING is most likely only happening when running appengine // locally, // but we should investigate to make sure BufferedReader reader = null; InputStreamReader isr = null; try {/* w ww. ja v a2 s. c om*/ reader = new BufferedReader(isr = new InputStreamReader(content, BasicConsts.UTF8_ENCODE)); String responseLine; while ((responseLine = reader.readLine()) != null) { response.append(responseLine); } } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } catch (IllegalStateException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } finally { try { if (reader != null) { reader.close(); } } catch (IOException ex) { // no-op } try { if (isr != null) { isr.close(); } } catch (IOException ex) { // no-op } } } return response.toString(); }
From source file:org.universAAL.android.proxies.ServiceCalleeProxy.java
/** * Extract the Service Profile information from the grounding. * /*w w w .ja v a 2 s . c o m*/ * @param parcel * The parcelable from of the grounding of the metadata. * @return The uAAL Service Profile. */ private static ServiceProfile[] prepareProfiles(String grounding) { MessageContentSerializerEx parser = (MessageContentSerializerEx) AndroidContainer.THE_CONTAINER .fetchSharedObject(AndroidContext.THE_CONTEXT, new Object[] { MessageContentSerializerEx.class.getName() });//TODO throw ex if error ServiceProfile sp = (ServiceProfile) parser.deserialize(grounding); String tenant = Config.getServerUSR(); try { tenant = URLEncoder.encode(tenant, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } // Matchmaking uses SP URI and Process URI (which is built from Service // URI) to distinguish callees, so these must be made unique for each // tenant despite being the same profile in each of them. sp.changeURI(sp.getURI() + tenant);// Add tenant ID to SP URI Service serv = sp.getTheService(); String servURI = serv.getURI(); serv.changeURI(servURI + tenant);// Add tenant ID to Service URI sp.setProperty(Service.PROP_OWLS_PRESENTED_BY, serv); String process = sp.getProcessURI();// Process URI = Service URI + "Process" (but maybe suffix will change in future?) String suffix = process.substring(servURI.length());// Get the "Process" suffix of the Process URI sp.changeProperty(ServiceProfile.PROP_OWLS_PROFILE_HAS_PROCESS, null);// Remove first cause doesnt work well sp.setProperty(ServiceProfile.PROP_OWLS_PROFILE_HAS_PROCESS, servURI + tenant + suffix);// Add tenant ID in Process URI return new ServiceProfile[] { sp }; }
From source file:org.universAAL.android.proxies.ServiceCalleeProxy.java
/** * Modify the serialized grounding to append tenant ID to relevant URIs. * Equivalent to prepareGrounding but returns it serialized. * /*from w w w. j a va 2s . com*/ * @param serial * The grounding of the metadata. * @return The modified uAAL Service Profile. */ private static String prepareGrounding(String grounding) { MessageContentSerializerEx parser = (MessageContentSerializerEx) AndroidContainer.THE_CONTAINER .fetchSharedObject(AndroidContext.THE_CONTEXT, new Object[] { MessageContentSerializerEx.class.getName() });//TODO throw ex if error ServiceProfile sp = (ServiceProfile) parser.deserialize(grounding); String tenant = Config.getServerUSR(); try { tenant = URLEncoder.encode(tenant, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } // Matchmaking uses SP URI and Process URI (which is built from Service // URI) to distinguish callees, so these must be made unique for each // tenant despite being the same profile in each of them. sp.changeURI(sp.getURI() + tenant);// Add tenant ID to SP URI Service serv = sp.getTheService(); String servURI = serv.getURI(); serv.changeURI(servURI + tenant);// Add tenant ID to Service URI sp.setProperty(Service.PROP_OWLS_PRESENTED_BY, serv); String process = sp.getProcessURI();// Process URI = Service URI + "Process" (but maybe suffix will change in future?) String suffix = process.substring(servURI.length());// Get the "Process" suffix of the Process URI sp.changeProperty(ServiceProfile.PROP_OWLS_PROFILE_HAS_PROCESS, null);// Remove first cause doesnt work well sp.setProperty(ServiceProfile.PROP_OWLS_PROFILE_HAS_PROCESS, servURI + tenant + suffix);// Add tenant ID in Process URI return parser.serialize(sp); }
From source file:org.opendatakit.common.utils.WebUtils.java
private static String readResponseHelper(InputStream content) { StringBuffer response = new StringBuffer(); if (content != null) { // TODO: this section of code is possibly causing 'WARNING: Going to // buffer // response body of large or unknown size. Using getResponseBodyAsStream // instead is recommended.' // The WARNING is most likely only happening when running appengine // locally, // but we should investigate to make sure BufferedReader reader = null; InputStreamReader isr = null; try {//ww w .j a v a 2s . c o m reader = new BufferedReader(isr = new InputStreamReader(content, HtmlConsts.UTF8_ENCODE)); String responseLine; while ((responseLine = reader.readLine()) != null) { response.append(responseLine); } } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } catch (IllegalStateException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } finally { try { if (reader != null) { reader.close(); } } catch (IOException ex) { // no-op } try { if (isr != null) { isr.close(); } } catch (IOException ex) { // no-op } } } return response.toString(); }
From source file:com.eryansky.common.utils.StringUtils.java
/** * ?utf8?//from w ww. j av a 2 s . com * * @param str * @return ???null * * <pre> * utf8Encode(null) = null * utf8Encode("") = ""; * utf8Encode("aa") = "aa"; * utf8Encode("") = "??"; * </pre> */ public static String utf8Encode(String str) { if (!isEmpty(str) && str.getBytes().length != str.length()) { try { return URLEncoder.encode(str, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } } return str; }
From source file:com.thoughtmetric.tl.TLLib.java
public static void postMessage(String message, String backurl, String topicId, Context context) throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setCookieStore(cookieStore); HttpPost httpost = new HttpPost(POST_URL); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("bericht", message)); nvps.add(new BasicNameValuePair("stage", "1")); nvps.add(new BasicNameValuePair("backurl", backurl)); nvps.add(new BasicNameValuePair("topic_id", topicId)); nvps.add(new BasicNameValuePair("submit_button", "Post")); try {// ww w. j ava 2 s. c om httpost.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response = httpclient.execute(httpost); HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } }
From source file:com.thoughtmetric.tl.TLLib.java
public static void sendPM(String to, String subject, String message) throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setCookieStore(cookieStore); HttpPost httpost = new HttpPost(PM_URL); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("to", to)); nvps.add(new BasicNameValuePair("subject", subject)); nvps.add(new BasicNameValuePair("body", message)); nvps.add(new BasicNameValuePair("view", "Send")); Log.d(TAG, "Sending message"); Log.d(TAG, to);// w w w . ja v a2 s. c o m Log.d(TAG, subject); Log.d(TAG, message); try { httpost.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response = httpclient.execute(httpost); HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } }
From source file:com.thoughtmetric.tl.TLLib.java
public static void editMessage(String message, int topicId, int postId, int currentPage, String token, Context context) throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setCookieStore(cookieStore); HttpPost httpost = new HttpPost(EDIT_URL); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("action", "edit")); nvps.add(new BasicNameValuePair("token", token)); nvps.add(new BasicNameValuePair("stage", "1")); nvps.add(new BasicNameValuePair("topic_id", Integer.toString(topicId))); nvps.add(new BasicNameValuePair("post_id", Integer.toString(postId))); nvps.add(new BasicNameValuePair("currentPage", Integer.toString(currentPage))); nvps.add(new BasicNameValuePair("content", message)); nvps.add(new BasicNameValuePair("submit_button", "Update")); try {//from w ww. jav a 2s . c o m httpost.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response = httpclient.execute(httpost); HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } }
From source file:com.thoughtmetric.tl.TLLib.java
public static void postNewThread(int forumCode, String subject, String message) throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setCookieStore(cookieStore); HttpPost httpost;/* w w w . j av a2 s . c om*/ List<NameValuePair> nvps = new ArrayList<NameValuePair>(); if (forumCode == 18) { httpost = new HttpPost(CREATE_NEW_BLOG_POST_URL); nvps.add(new BasicNameValuePair("topic_name", subject)); nvps.add(new BasicNameValuePair("bericht", message)); nvps.add(new BasicNameValuePair("stage", "1")); nvps.add(new BasicNameValuePair("submit", "Post Message")); nvps.add(new BasicNameValuePair("type", "")); } else { httpost = new HttpPost(CREATE_NEW_THREAD_URL); nvps.add(new BasicNameValuePair("topic_name", subject)); nvps.add(new BasicNameValuePair("content", message)); nvps.add(new BasicNameValuePair("submit", "Post Message")); nvps.add(new BasicNameValuePair("type", String.format("%d", forumCode))); } try { httpost.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response = httpclient.execute(httpost); HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } }
From source file:com.smallchill.core.toolbox.Func.java
public static String encodeUrl(String url) { try {/* www . j a v a 2s . com*/ url = isEmpty(url) ? "" : url; url = URLEncoder.encode(url, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return url; }