List of usage examples for java.io UnsupportedEncodingException getMessage
public String getMessage()
From source file:com.innovate.cms.common.web.Servlets.java
/** * ??Header./*from w w w . j a v a2s . c o m*/ * * @param fileName ???. */ public static void setFileDownloadHeader(HttpServletResponse response, String fileName) { try { // ??? String encodedfileName = new String(fileName.getBytes(), "ISO8859-1"); response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedfileName + "\""); } catch (UnsupportedEncodingException e) { e.getMessage(); } }
From source file:com.sm.transport.Utils.java
public static byte[] response2Bytes(Response response) { if (response.getPayload() instanceof String) { try {//w ww . ja v a 2s. com byte[] d = ((String) response.getPayload()).getBytes("UTF-8"); byte[] toReturn = new byte[d.length + 1]; toReturn[0] = (byte) (response.isError() ? 1 : 0); System.arraycopy(d, 0, toReturn, 1, d.length); return toReturn; } catch (UnsupportedEncodingException e) { logger.error(e.getMessage()); return new byte[] { (byte) (response.isError() ? 1 : 0) }; } } else { return new byte[] { (byte) (response.isError() ? 1 : 0) }; } }
From source file:com.ibm.sbt.security.authentication.oauth.consumer.OAuthHandler.java
public static String percentEncode(String str) { String encodedStr = null;/* w ww . j av a 2 s . c om*/ if (!StringUtil.isEmpty(str)) { try { encodedStr = URLEncoder.encode(str, Configuration.ENCODING).replace("+", "%20").replace("*", "%2A") .replace("%7E", "~"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage()); } } return encodedStr; }
From source file:fr.paris.lutece.plugins.gru.service.ActionLinkService.java
/** * Build a link to display a given URL into a frame * /*from w ww .j a v a2 s . com*/ * @param strUrl * The input URL * @param customer * The customer * @return The frame URL */ private static String buildFrameLink(String strUrl, Customer customer) { String strLink; try { strLink = URLEncoder.encode(strUrl, "UTF-8"); UrlItem url = new UrlItem(URL_JSP_FRAME_VIEW); url.addParameter(Constants.PARAMETER_URL_FRAME, strLink); if (customer != null) { url.addParameter(Constants.PARAMETER_ID_CUSTOMER, customer.getId()); } return url.getUrl(); } catch (UnsupportedEncodingException ex) { AppLogService.error("Error encoding url " + ex.getMessage(), ex); return ""; } }
From source file:eu.skillpro.ams.pscm.connector.amsservice.ui.SendExecutableSkillToServer.java
protected static String fixEncoding(String latin1) { try {/* www . j a v a 2 s.c o m*/ String url = URLEncoder.encode(latin1, "UTF-8"); byte[] bytes = url.getBytes("ISO-8859-1"); if (!validUTF8(bytes)) return url; return new String(bytes, "UTF-8"); } catch (UnsupportedEncodingException e) { // Impossible, throw unchecked throw new IllegalStateException("No Latin1 or UTF-8: " + e.getMessage()); } }
From source file:ch.entwine.weblounge.test.util.TestSiteUtils.java
/** * Loads the greetings from <code>/greetings.properties</code> into a * <code>Map</code> and returns them. * <p>/* w w w . j av a 2s .com*/ * Note that we need to do a conversion from the <code>ISO-LATIN-1</code> * (which is assumed by the <code>Properties</code> implementation) to * <code>utf-8</code>. * * @return the greetings * @throws Exception * if loading fails */ public static Map<String, String> loadGreetings() { Map<String, String> greetings = new HashMap<String, String>(); InputStream is = TestSiteUtils.class.getResourceAsStream(GREETING_PROPS); try { Properties props = new Properties(); props.load(is); for (Entry<Object, Object> entry : props.entrySet()) { try { String isoLatin1Value = entry.getValue().toString(); String utf8Value = new String(isoLatin1Value.getBytes("ISO-8859-1"), "utf-8"); greetings.put((String) entry.getKey(), utf8Value); } catch (UnsupportedEncodingException e) { logger.error("I can't believe the platform does not support encoding {}", e.getMessage()); } } } catch (IOException e) { logger.error("Error reading greetings from " + GREETING_PROPS, e); return null; } finally { IOUtils.closeQuietly(is); } return greetings; }
From source file:com.emaxcore.emaxdata.common.web.Servlets.java
/** * ??Header./*from w ww . ja v a 2 s . c o m*/ * * @param fileName ???. */ public static void setFileDownloadHeader(HttpServletResponse response, String fileName) { try { // ??? String encodedfileName = new String(fileName.getBytes(), "ISO8859-1"); response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedfileName + "\""); } catch (UnsupportedEncodingException e) { logger.warn(e + ""); e.getMessage(); } }
From source file:crow.weibo.util.WeiboUtil.java
/** * ??/* ww w .ja v a2s . com*/ * * @param value * @return */ public static String encode(String s) { if (s == null) { return ""; } try { return URLEncoder.encode(s, "UTF-8").replace("+", "%20").replace("*", "%2A").replace("%7E", "~") .replace("#", "%23"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.liferay.portal.security.pwd.PwdEncryptor.java
public static String encodePassword(String algorithm, String clearTextPassword, byte[] saltBytes) throws PwdEncryptorException { try {/*from www .j a v a 2s . co m*/ if (algorithm.equals(TYPE_BCRYPT)) { String salt = new String(saltBytes); return null; // BCrypt.hashpw(clearTextPassword, salt); } else if (algorithm.equals(TYPE_CRYPT) || algorithm.equals(TYPE_UFC_CRYPT)) { return null; // Crypt.crypt( //saltBytes, clearTextPassword.getBytes(Digester.ENCODING)); } else if (algorithm.equals(TYPE_SSHA)) { byte[] clearTextPasswordBytes = clearTextPassword.getBytes("UTF8");//Digester.ENCODING); // Create a byte array of salt bytes appended to password bytes byte[] pwdPlusSalt = new byte[clearTextPasswordBytes.length + saltBytes.length]; System.arraycopy(clearTextPasswordBytes, 0, pwdPlusSalt, 0, clearTextPasswordBytes.length); System.arraycopy(saltBytes, 0, pwdPlusSalt, clearTextPasswordBytes.length, saltBytes.length); // Digest byte array MessageDigest sha1Digest = MessageDigest.getInstance("SHA-1"); byte[] pwdPlusSaltHash = sha1Digest.digest(pwdPlusSalt); // Appends salt bytes to the SHA-1 digest. byte[] digestPlusSalt = new byte[pwdPlusSaltHash.length + saltBytes.length]; System.arraycopy(pwdPlusSaltHash, 0, digestPlusSalt, 0, pwdPlusSaltHash.length); System.arraycopy(saltBytes, 0, digestPlusSalt, pwdPlusSaltHash.length, saltBytes.length); // Base64 encode and format string return ByteArray.toBase64String(digestPlusSalt); //return Base64.encode(digestPlusSalt); } else { return null; // DigesterUtil.digest(algorithm, clearTextPassword); } } catch (NoSuchAlgorithmException nsae) { throw new PwdEncryptorException(nsae.getMessage()); } catch (UnsupportedEncodingException uee) { throw new PwdEncryptorException(uee.getMessage()); } }
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 www. ja v a2s .c o m*/ 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"); }