List of usage examples for java.io UnsupportedEncodingException getMessage
public String getMessage()
From source file:org.akvo.flow.api.FlowApi.java
private static String getImei(Context context) { try {//from w w w . j a v a2 s. com String imei = StatusUtil.getImei(context); if (imei != null) { return URLEncoder.encode(StatusUtil.getImei(context), "UTF-8"); } return ""; } catch (UnsupportedEncodingException e) { Log.e(TAG, e.getMessage()); return null; } }
From source file:illab.nabal.util.ParameterHelper.java
/** * URL-decodes bundle parameters. /*ww w . ja v a 2s . co m*/ * (x-www-form-urlencoded MIME content type) * * @param queryString - query string parameters * @return Bundle */ public static Bundle decodeGetParams(String queryString) { Bundle params = new Bundle(); if (queryString != null) { String[] array = queryString.split(AMPERSEND); for (String parameter : array) { String[] nvPair = parameter.split(EQUAL_MARK); try { params.putString(URLDecoder.decode(nvPair[0], UTF_8), URLDecoder.decode(nvPair[1], UTF_8)); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.getMessage()); Log.e(TAG, "Failed to decode parameter : " + parameter); } } } return params; }
From source file:com.sm.message.Header.java
public static Header toHeader(byte[] data) { ByteBuffer buf = ByteBuffer.wrap(data); byte release = buf.get(); long version = buf.getLong(); long node = buf.getLong(); byte[] n = new byte[data.length - FIRST]; buf.get(n);/*from w w w. j a v a 2s . c om*/ try { String name = new String(n, "UTF-8"); return new Header(name, version, release, node); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex.getMessage()); } }
From source file:de.escidoc.core.common.servlet.UserHandleCookieUtil.java
/** * Create Base46-Encoded userHandle./*from w w w . j a v a 2s.c o m*/ * * @param userHandle userHandle * @return the encoded userHandle. * @throws WebserverSystemException e */ public static String createEncodedUserHandle(final String userHandle) throws WebserverSystemException { try { return new String(Base64.encodeBase64(userHandle.getBytes(XmlUtility.CHARACTER_ENCODING)), XmlUtility.CHARACTER_ENCODING); } catch (final UnsupportedEncodingException e) { throw new WebserverSystemException( StringUtility.format("Can't encode UserHandle Base64", e.getMessage()), e); } }
From source file:de.escidoc.core.common.servlet.UserHandleCookieUtil.java
/** * Create Base46-Encoded userHandle.// w w w . j a v a 2s . c o m * * @param userHandle userHandle * @return the decoded userHandle. * @throws WebserverSystemException e */ public static String createDecodedUserHandle(final String userHandle) throws WebserverSystemException { try { return new String(Base64.decodeBase64(userHandle.getBytes(XmlUtility.CHARACTER_ENCODING)), XmlUtility.CHARACTER_ENCODING); } catch (final UnsupportedEncodingException e) { throw new WebserverSystemException( StringUtility.format("Can't decode UserHandle Base64", e.getMessage()), e); } }
From source file:de.vanita5.twittnuker.util.shortener.TweetShortenerUtils.java
/** * Shorten long tweets with hotot.in/*from w ww . ja va 2s .c om*/ * @param context * @param text * @param accounts * @return shortened tweet */ public static String shortWithHototin(final Context context, final String text, final Account[] accounts) { String screen_name = null; String avatar_url = null; if (accounts != null && accounts.length > 0) { screen_name = getAccountScreenName(context, accounts[0].account_id); avatar_url = getAccountProfileImage(context, accounts[0].account_id); avatar_url = avatar_url != null && !avatar_url.isEmpty() ? avatar_url : DEFAULT_AVATAR_URL; } try { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(HOTOTIN_URL); MultipartEntity requestEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); requestEntity.addPart(HOTOTIN_ENTITY_NAME, new StringBody(screen_name)); requestEntity.addPart(HOTOTIN_ENTITY_AVATAR, new StringBody(avatar_url)); requestEntity.addPart(HOTOTIN_ENTITY_TEXT, new StringBody(text, Charset.forName("UTF-8"))); httpPost.setEntity(requestEntity); InputStream responseStream; BufferedReader br; HttpResponse response = httpClient.execute(httpPost); HttpEntity responseEntity = response.getEntity(); responseStream = responseEntity.getContent(); br = new BufferedReader(new InputStreamReader(responseStream)); String responseLine = br.readLine(); String tmpResponse = ""; while (responseLine != null) { tmpResponse += responseLine + System.getProperty("line.separator"); responseLine = br.readLine(); } br.close(); JSONObject jsonObject = new JSONObject(tmpResponse); String result = jsonObject.getString("text"); return result; } catch (UnsupportedEncodingException e) { if (Utils.isDebugBuild()) Log.e(LOG_TAG, e.getMessage()); e.printStackTrace(); } catch (ClientProtocolException e) { if (Utils.isDebugBuild()) Log.e(LOG_TAG, e.getMessage()); e.printStackTrace(); } catch (IOException e) { if (Utils.isDebugBuild()) Log.e(LOG_TAG, e.getMessage()); e.printStackTrace(); } catch (JSONException e) { if (Utils.isDebugBuild()) Log.e(LOG_TAG, e.getMessage()); e.printStackTrace(); } return null; }
From source file:biblivre3.marcutils.MarcReader.java
public static Record marcToRecord(final String marc, final MaterialType mt, final RecordStatus status) { final String splitter = detectSplitter(marc); final String escaped = HtmlEntityEscaper.replaceHtmlEntities(marc); Scanner scanner = null;// w w w . ja v a 2 s. c o m try { final ByteArrayInputStream bais = new ByteArrayInputStream(escaped.getBytes("UTF-8")); scanner = new Scanner(bais, "UTF-8"); } catch (UnsupportedEncodingException uee) { log.error(uee.getMessage(), uee); scanner = new Scanner(escaped); } final List<String> text = new ArrayList<String>(); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line.trim().length() > 3) { text.add(line); } } final String tags[] = new String[text.size()]; final String values[] = new String[text.size()]; for (int i = 0; i < text.size(); i++) { final String line = text.get(i); if (!line.toUpperCase().startsWith("LEADER")) { tags[i] = line.substring(0, 3).toUpperCase(); values[i] = line.substring(4, text.get(i).length()).trim(); } else { tags[i] = line.substring(0, 6).toUpperCase(); values[i] = line.substring(7, text.get(i).length()).trim(); } } final Leader leader = setLeader(tags, values, mt, status); final MarcFactory factory = MarcFactory.newInstance(); final Record record = factory.newRecord(leader); setControlFields(record, tags, values); setDataFields(record, tags, values, splitter); return record; }
From source file:com.jivesoftware.sdk.utils.JiveSDKUtils.java
public static String decodeUrl(@Nonnull String url) { try {/*from w w w . j ava 2 s.c o m*/ return URLDecoder.decode(url, "UTF-8"); } catch (UnsupportedEncodingException uee) { //TODO: LOGGER System.err.println("Failed decoding URL using UTF-8 charset" + uee.getMessage()); //noinspection deprecation return URLDecoder.decode(url); } }
From source file:com.jivesoftware.sdk.utils.JiveSDKUtils.java
@Nonnull public static String encodeUrl(@Nonnull String url) { try {/* w w w. j a v a 2 s . c o m*/ return URLEncoder.encode(url, "UTF-8"); } catch (UnsupportedEncodingException uee) { //TODO: LOGGER System.err.println("Failed encoding URL using UTF-8 charset" + uee.getMessage()); //noinspection deprecation return URLEncoder.encode(url); } }
From source file:org.guohai.android.cta.utility.HttpRest.java
/** * HTTPPost?//from w ww . ja v a 2 s. c o m * @param url POST? * @param pairs ? * @return ?JOSN?null */ public static ResultInfo HttpPostClient(String url, List<NameValuePair> pairs) { //create http client HttpClient client = new DefaultHttpClient(); //create post request HttpPost httpPost = new HttpPost(url); //return value ResultInfo result = new ResultInfo(); //init eroor value result.State = -1000; result.Message = "posterror"; HttpEntity entity; try { entity = new UrlEncodedFormEntity(pairs, HTTP.UTF_8); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); Log.e(TAG, e.getMessage()); return result; } httpPost.setEntity(entity); //??POST? try { HttpResponse response = client.execute(httpPost); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entityHtml = response.getEntity(); BufferedReader reader = new BufferedReader(new InputStreamReader(entityHtml.getContent(), "UTF-8")); String line = null; String reString = ""; while ((line = reader.readLine()) != null) { reString += line; } if (entityHtml != null) { entityHtml.consumeContent(); } Log.i(TAG, reString); JSONObject jsonObj; try { jsonObj = new JSONObject(reString); result.State = jsonObj.getInt("state"); result.Message = jsonObj.getString("message"); return result; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); Log.e(TAG, e.getMessage()); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); Log.e(TAG, e.getMessage()); } return result; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); Log.e(TAG, e.getMessage()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); Log.e(TAG, e.getMessage()); } return result; }