Example usage for java.io UnsupportedEncodingException getMessage

List of usage examples for java.io UnsupportedEncodingException getMessage

Introduction

In this page you can find the example usage for java.io UnsupportedEncodingException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.jivesoftware.sdk.util.JiveSDKUtils.java

public static String encodeUrl(String url) {
    try {/*from   ww w . ja  v  a2  s  . c  o m*/
        return URLEncoder.encode(url, StandardCharsets.UTF_8.name());
    } catch (UnsupportedEncodingException uee) {
        log.warn("Failed encoding URL using UTF-8 charset" + uee.getMessage());
        //noinspection deprecation
        return url;
    } // end try/catch
}

From source file:net.sourceforge.fenixedu.util.tests.ResponseExternalization.java

public static String externalize(Response source) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(out);
    encoder.writeObject(source);//from  w ww. jav a2  s  . c o m
    encoder.close();
    try {
        // I think that this is wrong and that we should get the
        // bytes of the ByteArrayOutputStream interpreted as
        // UTF-8, which is what the XMLEncoder produces in the
        // first place.
        // WARNING: If this is changed, the internalize method
        // should be changed accordingly.
        return out.toString(Charset.defaultCharset().name());
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        logger.error(e.getMessage(), e);
        return out.toString();
    }
}

From source file:com.ibm.sbt.security.encryption.HMACEncryptionUtility.java

public static String percentEncode(String str) {
    String encodedStr = null;/*w  ww.  j a v  a2  s . c  o m*/
    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:cn.crawin.msg.gateway.http.MessageDigestUtil.java

/**
 * UTF-8??ISO-9959-1/*from www  . ja  v a2s. c o m*/
 *
 * @param str
 * @return
 */
public static String utf8ToIso88591(String str) {
    if (str == null) {
        return str;
    }

    try {
        return new String(str.getBytes("UTF-8"), "ISO-8859-1");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:cn.crawin.msg.gateway.http.MessageDigestUtil.java

/**
 * ISO-9959-1??UTF-8/*from w w  w .j  av  a  2 s .  c  o  m*/
 *
 * @param str
 * @return
 */
public static String iso88591ToUtf8(String str) {
    if (str == null) {
        return str;
    }

    try {
        return new String(str.getBytes("ISO-8859-1"), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:cn.crawin.msg.gateway.http.MessageDigestUtil.java

/**
 * String?//from w  ww  . java 2 s.c om
 *
 * @param str
 * @return
 */
private static byte[] toBytes(final String str) {
    if (str == null) {
        return null;
    }
    try {
        return str.getBytes(Constants.ENCODING);
    } catch (final UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:com.microsoft.aad.adal.HashMapExtensions.java

/**
 * decode url string into a key value pairs with given query delimiter given
 * string as a=1&b=2 will return key value of [[a,1],[b,2]].
 * /*from w ww. j av  a2  s  .c o  m*/
 * @param parameters
 * @param delimiter
 * @return key value pairs
 */
static final HashMap<String, String> URLFormDecodeData(String parameters, String delimiter) {
    HashMap<String, String> result = new HashMap<String, String>();

    if (!StringExtensions.IsNullOrBlank(parameters)) {
        StringTokenizer parameterTokenizer = new StringTokenizer(parameters, delimiter);

        while (parameterTokenizer.hasMoreTokens()) {
            String pair = parameterTokenizer.nextToken();
            String[] elements = pair.split("=");

            if (elements != null && elements.length == 2) {
                String key = null;
                String value = null;
                try {
                    key = StringExtensions.URLFormDecode(elements[0].trim());
                    value = StringExtensions.URLFormDecode(elements[1].trim());
                } catch (UnsupportedEncodingException e) {
                    Log.d(TAG, e.getMessage());
                }

                if (!StringExtensions.IsNullOrBlank(key) && !StringExtensions.IsNullOrBlank(value)) {
                    result.put(key, value);
                }
            }
        }
    }

    return result;
}

From source file:qc.web.util.WebUtils.java

/**????????
 * @param request/*from   w  ww . j  a v  a2 s.c  o m*/
 * @param srcFileName ??
 * @return ????
 */
public static String encodeFileName(HttpServletRequest request, String srcFileName) {
    String _fileName;
    // ???
    boolean isIE = request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") != -1;
    try {
        if (isIE) {// IE?
            _fileName = URLEncoder.encode(srcFileName, "UTF-8");
            if (_fileName.length() > 150) {
                // URLEncoder?17IE6 IEbug??KB816868
                // ?????ie6 sp1
                String guessCharset = "gb2312"; //?requestlocale???gb2312
                _fileName = new String(srcFileName.getBytes(guessCharset), "ISO8859-1");
            }
        } else {// ?IE?:?URLEncoder.encode???url?
            _fileName = new String(srcFileName.getBytes("UTF-8"), "ISO8859-1");
        }
    } catch (UnsupportedEncodingException e) {
        logger.warn(e.getMessage());
        _fileName = srcFileName;
    }
    return _fileName;
}

From source file:com.alibaba.openapi.client.util.SignatureUtil.java

public static byte[] toBytes(final String str) {
    if (str == null) {
        return null;
    }//from  www . j a va 2 s. c o  m
    try {
        return str.getBytes(CHARSET_NAME_UTF8);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:com.barrybecker4.common.util.Base64Codec.java

/**
 * take a String and compress it./*from  w  w w  .  j a  v a  2s . c o m*/
 * See @decompress for reversing the compression.
 * @param data a string to compress.
 * @return compressed string representation.
 */
public static synchronized String compress(final String data) {

    ByteArrayOutputStream byteOut = new ByteArrayOutputStream(512);
    Deflater deflater = new Deflater();
    DeflaterOutputStream oStream = new DeflaterOutputStream(byteOut, deflater);

    try {
        oStream.write(data.getBytes(CONVERTER_UTF8));
        oStream.flush();
        oStream.close();
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException("Unsupported encoding exception :" + e.getMessage(), e);
    } catch (IOException e) {
        throw new IllegalStateException("io error :" + e.getMessage(), e);
    }

    return new String(Base64.encodeBase64(byteOut.toByteArray()));
}