List of usage examples for java.io UnsupportedEncodingException getMessage
public String getMessage()
From source file:lti.oauth.OAuthUtil.java
public static String percentEncode(String s) { if (s == null) { return ""; }/*from w w w . j av a2s . co m*/ try { return URLEncoder.encode(s, ENCODING) // OAuth encodes some characters differently: .replace("+", "%20").replace("*", "%2A").replace("%7E", "~"); } catch (UnsupportedEncodingException uee) { throw new RuntimeException(uee.getMessage(), uee); } }
From source file:org.envirocar.app.network.RestClient.java
public static void updateAcceptedTermsOfUseVersion(User user, String issuedDate, AsyncHttpResponseHandler handler) { String contents = String.format("{\"%s\": \"%s\"}", "acceptedTermsOfUseVersion", issuedDate); try {/*w w w.j a v a2 s.co m*/ put(ECApplication.BASE_URL + "/users/" + user.getUsername(), handler, contents, user.getUsername(), user.getToken()); } catch (UnsupportedEncodingException e) { logger.warn(e.getMessage(), e); } }
From source file:com.barrybecker4.common.util.Base64Codec.java
/** * Take a String and decompress it.//from w w w . j a v a 2 s . c o m * @param data the compressed string to decompress. * @return the decompressed string. */ public static synchronized String decompress(final String data) { // convert from string to bytes for decompressing byte[] compressedDat = Base64.decodeBase64(data.getBytes()); final ByteArrayInputStream in = new ByteArrayInputStream(compressedDat); final Inflater inflater = new Inflater(); final InflaterInputStream iStream = new InflaterInputStream(in, inflater); final char cBuffer[] = new char[4096]; StringBuilder sBuf = new StringBuilder(); try { InputStreamReader iReader = new InputStreamReader(iStream, CONVERTER_UTF8); while (true) { final int numRead = iReader.read(cBuffer); if (numRead == -1) { break; } sBuf.append(cBuffer, 0, numRead); } } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("Unsupported encoding exception :" + e.getMessage(), e); } catch (IOException e) { throw new IllegalStateException("io error :" + e.getMessage(), e); } return sBuf.toString(); }
From source file:com.casewaresa.framework.util.LegacyJasperInputStream.java
public static InputStream convertStringToInputStream(final String template) { InputStream is = null;/*from ww w . ja v a 2 s. co m*/ try { if (SystemUtils.IS_OS_WINDOWS) { log.trace("### Cargando el objeto desde un ambiente WINDOWS"); is = new ByteArrayInputStream(template.getBytes("UTF-8")); } else if (SystemUtils.IS_OS_LINUX) { log.trace("### Cargando el objeto desde un ambiente UNIX (LINUX)"); is = new ByteArrayInputStream(template.getBytes()); } else if (SystemUtils.IS_OS_MAC) { log.trace("### Cargando el objeto desde un ambiente MAC"); is = new ByteArrayInputStream(template.getBytes("UTF-8")); } } catch (UnsupportedEncodingException ex) { log.debug(ex.getMessage(), ex); } return is; }
From source file:com.alibaba.openapi.client.util.SignatureUtil.java
public static String getKeyString(SecretKeySpec key) { try {// w w w. j ava 2 s . c o m return new String(key.getEncoded(), CHARSET_NAME_UTF8); } catch (UnsupportedEncodingException e) { throw new RuntimeException("key format error:" + e.getMessage()); } }
From source file:com.npower.dm.util.DMUtil.java
/** * Append a parameter into URL/*from w w w . j av a 2 s . co m*/ * @param url * @param parameterName * @param parameterValue * @return */ public static String appendParameter(String url, String parameterName, String parameterValue) { StringBuffer result = new StringBuffer(url); if (StringUtils.isEmpty(parameterName)) { return result.toString(); } if (url.indexOf('?') > 0) { result.append('&'); } else { result.append('?'); } result.append(parameterName); result.append('='); try { result.append(URLEncoder.encode(parameterValue, "UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } return result.toString(); }
From source file:com.jivesoftware.sdk.util.JiveSDKUtils.java
public static String decodeUrl(String url) { try {/*from w w w . ja v a 2s. c om*/ return URLDecoder.decode(url, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException uee) { //TODO: LOGGER System.err.println("Failed decoding URL using UTF-8 charset" + uee.getMessage()); //noinspection deprecation return url; } }
From source file:org.envirocar.app.network.RestClient.java
/** * @deprecated Use {@link DAOProvider#getSensorDAO()} / {@link SensorDAO#saveSensor(org.envirocar.app.model.Car, User)} * instead./*from w w w. ja v a 2s . c om*/ */ @Deprecated public static boolean createSensor(String jsonObj, String user, String token, AsyncHttpResponseHandler handler) { client.addHeader("Content-Type", "application/json"); setHeaders(user, token); try { StringEntity se = new StringEntity(jsonObj); se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); client.post(null, ECApplication.BASE_URL + "/sensors", se, "application/json", handler); } catch (UnsupportedEncodingException e) { logger.warn(e.getMessage(), e); return false; } return true; }
From source file:com.jsmartframework.web.manager.TagEncrypter.java
static void init() { try {//w ww . j a v a2 s.c om String customKey = CONFIG.getContent().getTagSecretKey(); if (StringUtils.isNotBlank(customKey)) { if (customKey.length() != CYPHER_KEY_LENGTH) { throw new RuntimeException("Custom tag-secret-key must have its value " + "with [" + CYPHER_KEY_LENGTH + "] characters"); } secretKey = new SecretKeySpec(customKey.getBytes("UTF8"), "AES"); } else { secretKey = new SecretKeySpec(DEFAULT_KEY.getBytes("UTF8"), "AES"); } } catch (UnsupportedEncodingException ex) { LOGGER.log(Level.INFO, "Failed to generate key secret for tag: " + ex.getMessage()); } }
From source file:Main.java
public static String getMD5Value(String str, String fix, String charsetName) { if (str != null && fix != null) { String formalString = str + fix; try {// w w w. jav a 2 s.c o m MessageDigest algorithm = MessageDigest.getInstance("MD5"); algorithm.reset(); try { algorithm.update(formalString.getBytes(charsetName)); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block Log.e("WxException", e.getMessage(), e); return null; } byte messageDigest[] = algorithm.digest(); return toHexString(messageDigest); } catch (NoSuchAlgorithmException e) { Log.w(TAG, e); Log.e("WxException", e.getMessage(), e); } } return null; }