List of usage examples for java.io UnsupportedEncodingException toString
public String toString()
From source file:eionet.cr.web.action.SpatialSearchActionBean.java
/** * * @return//from w w w. j a v a2 s. c om * @throws DAOException */ private Resolution doKml() throws DAOException { logger.debug("KML requested, BBOX = " + this.bbox); String[] ltudes = this.bbox.split(","); if (ltudes != null && ltudes.length == 4) { longW = Util.toDouble(ltudes[0].trim()); latS = Util.toDouble(ltudes[1].trim()); longE = Util.toDouble(ltudes[2].trim()); latN = Util.toDouble(ltudes[3].trim()); SortingRequest sortingRequest = new SortingRequest(Predicates.RDFS_LABEL, SortOrder.ASCENDING); sortingRequest.setSortByPredicateObjectHash(true); Pair<Integer, List<SubjectDTO>> resultPair = DAOFactory.get().getDao(SearchDAO.class) .searchBySpatialBox(createBBOX(), source, PagingRequest.create(1, 25), sortingRequest, true); resultList = resultPair.getRight(); } try { getContext().getRequest().setCharacterEncoding("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.toString(), e); } getContext().getResponse().setHeader("Content-Disposition", "attachment; filename=placemarks.kml"); return new ForwardResolution("/pages/placemarks.jsp"); }
From source file:com.xorcode.andtweet.net.ConnectionBasicAuth.java
/** * Retrieve the input stream from the HTTP connection. * /*from ww w. j a va 2s. c om*/ * @param httpEntity * @return String */ private String retrieveInputStream(HttpEntity httpEntity) { int length = (int) httpEntity.getContentLength(); StringBuffer stringBuffer = new StringBuffer(length); try { InputStreamReader inputStreamReader = new InputStreamReader(httpEntity.getContent(), HTTP.UTF_8); char buffer[] = new char[length]; int count; while ((count = inputStreamReader.read(buffer, 0, length - 1)) > 0) { stringBuffer.append(buffer, 0, count); } } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } catch (IllegalStateException e) { Log.e(TAG, e.toString()); } catch (IOException e) { Log.e(TAG, e.toString()); } return stringBuffer.toString(); }
From source file:sawtooth.examples.xo.XoHandler.java
/** * Helper function to generate game address. */// w w w .java 2 s . c o m private String makeGameAddress(String gameName) throws InternalError { try { String hashedName = Utils.hash512(gameName.getBytes("UTF-8")); return xoNameSpace + hashedName.substring(0, 64); } catch (UnsupportedEncodingException e) { throw new InternalError("Internal Error: " + e.toString()); } }
From source file:com.xorcode.andtweet.net.ConnectionBasicAuth.java
@Override public JSONObject updateStatus(String message, long inReplyToId) throws ConnectionException { String url = STATUSES_UPDATE_URL; List<NameValuePair> formParams = new ArrayList<NameValuePair>(); formParams.add(new BasicNameValuePair("status", message)); // This parameter was removed from API: // formParams.add(new BasicNameValuePair("source", SOURCE_PARAMETER)); if (inReplyToId > 0) { formParams.add(new BasicNameValuePair("in_reply_to_status_id", String.valueOf(inReplyToId))); }/*from w w w .j a v a 2 s . com*/ JSONObject jObj = null; try { jObj = new JSONObject(postRequest(url, new UrlEncodedFormEntity(formParams, HTTP.UTF_8))); String error = jObj.optString("error"); if ("Could not authenticate you.".equals(error)) { throw new ConnectionException(error); } } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } catch (JSONException e) { throw new ConnectionException(e); } return jObj; }
From source file:cn.edu.zzu.wemall.http.AsyncHttpResponseHandler.java
/** * Fired when a request returns successfully, override to handle in your own code * * @param statusCode the status code of the response * @param headers return headers, if any * @param responseBody the body of the HTTP response from the server *//*from w w w . jav a2s . c om*/ public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { try { String response = new String(responseBody, getCharset()); onSuccess(statusCode, headers, response); } catch (UnsupportedEncodingException e) { Log.e(LOG_TAG, e.toString()); onFailure(statusCode, headers, e, null); } }
From source file:cn.edu.zzu.wemall.http.AsyncHttpResponseHandler.java
/** * Fired when a request fails to complete, override to handle in your own code * * @param statusCode return HTTP status code * @param headers return headers, if any * @param responseBody the response body, if any * @param error the underlying cause of the failure *//* ww w . j a va 2s. com*/ public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { String response; try { response = new String(responseBody, getCharset()); onFailure(statusCode, headers, error, response); } catch (UnsupportedEncodingException e) { Log.e(LOG_TAG, e.toString()); onFailure(statusCode, headers, e, null); } }
From source file:net.issarlk.androbunny.inkbunny.API.java
public Search searchText(String text, int fields, int dayslimit) throws InkbunnyAPIException { Search result;//from w w w . j a va 2 s .c o m try { result = new Search(this.sid, "text=" + URLEncoder.encode(text, "UTF-8") + "&keywords=" + (((fields & SEARCH_KEYWORDS) != 0) ? "yes" : "no") + "&title=" + (((fields & SEARCH_TITLES) != 0) ? "yes" : "no") + "&description=" + (((fields & SEARCH_DESCRIPTIONS) != 0) ? "yes" : "no") + ((dayslimit > 0) ? "&dayslimit=" + dayslimit : "")); result.description = "Search results for " + text; return result; } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); return null; } }
From source file:org.transdroid.daemon.Ttorrent.TtorrentAdapter.java
private String makeRequest(Log log, String path, NameValuePair... params) throws DaemonException { try {//from www. ja v a 2s . c om // Setup request using POST HttpPost httppost = new HttpPost(buildWebUIUrl(path)); List<NameValuePair> nvps = new ArrayList<>(); Collections.addAll(nvps, params); httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); return makeWebRequest(httppost, log); } catch (UnsupportedEncodingException e) { throw new DaemonException(ExceptionType.ConnectionError, e.toString()); } }
From source file:org.ireland.jnetty.util.http.URIDecoder.java
private String byteToChar(byte[] buffer, int offset, int length, String encoding) { ByteToChar converter = allocateConverter(); // XXX: make this configurable if (encoding == null) encoding = "utf-8"; try {/*from w w w . j a v a2 s . c o m*/ converter.setEncoding(encoding); } catch (UnsupportedEncodingException e) { log.debug(e.toString(), e); } String result; try { for (; length > 0; length--) converter.addByte(buffer[offset++]); result = converter.getConvertedString(); freeConverter(converter); } catch (IOException e) { result = "unknown"; } return result; }
From source file:hudson.org.apache.tools.ant.taskdefs.cvslib.ChangeLogTask.java
/** * Print changelog to file specified in task. * * @param entrySet the entry set to write. * @throws BuildException if there is an error writing changelog. *///from w w w . ja va 2 s . c o m private void writeChangeLog(final CVSEntry[] entrySet) throws BuildException { OutputStream output = null; try { output = m_output; final PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, "UTF-8")); final ChangeLogWriter serializer = new ChangeLogWriter(); serializer.printChangeLog(writer, entrySet); } catch (final UnsupportedEncodingException uee) { getProject().log(uee.toString(), Project.MSG_ERR); } catch (final IOException ioe) { throw new BuildException(ioe.toString(), ioe); } finally { IOUtils.closeQuietly(output); } }