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.vmware.bdd.utils.CommonUtil.java

public static String decode(final String paramName) {
    try {// w w  w.  j  a v  a  2  s  .  c om
        return URLDecoder.decode(paramName, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        logger.error(e.getMessage(), e);
        return paramName;
    }
}

From source file:com.vmware.bdd.utils.CommonUtil.java

public static String encode(final String paramName) {
    try {// w w w. j av  a2  s  .  com
        return URLEncoder.encode(paramName, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        logger.error(e.getMessage(), e);
        return paramName;
    }
}

From source file:be.jcdo.mp3searchengines.tools.URIUtils.java

/**
 * Convert a target string from the fromCharset charset to
 * the toCharset charset./*from www  .j ava 2 s  .c  om*/
 * 
        
 * What if the document charset is ISO-8859-1 and the protocol charset is
 * UTF-8, when it's read from the document part and is used in the protocol
 * part, the use of the method will be toUsingCharset(the string,
 * "ISO-8859-1", "UTF-8").
 *
 * @param target a target string
 * @param fromCharset the previous charset
 * @param toCharset the changing charset
 * @return the document character encoded string
 * 
 * @throws URIException if either of the charsets are not supported
 * 
 * @deprecated Do not use. To be removed
 */

public static String toUsingCharset(String target, String fromCharset, String toCharset) throws URIException {

    try {
        return new String(target.getBytes(fromCharset), toCharset);
    } catch (UnsupportedEncodingException error) {
        throw new URIException(URIException.UNSUPPORTED_ENCODING, error.getMessage());
    }
}

From source file:jp.terasoluna.fw.validation.ValidationUtil.java

/**
 * ?????????????//  w  w w  .  j  av  a2  s .co m
 * ????????????
 * ??
 *
 * <code>null</code> ???????
 *
 * @param value 
 * @param encoding ???<code>encoding</code>??
 * @param min 
 * @param max ?
 * @return
 *            ???????
 *            ????<code>true</code>?
 *            ?????<code>false</code>?
 */
public static boolean isByteInRange(String value, String encoding, int min, int max) {

    // ?null?????true?
    if (StringUtils.isEmpty(value)) {
        return true;
    }

    // ???
    int bytesLength = 0;
    try {
        bytesLength = StringUtil.getByteLength(value, encoding);
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException(e.getMessage());
    }

    // ??
    if (!GenericValidator.isInRange(bytesLength, min, max)) {
        return false;
    }
    return true;
}

From source file:com.aurel.track.exchange.docx.exporter.AssembleWordprocessingMLPackage.java

/**
 * Transform the html content to word content
 * @param wordMLPackage/*  w w w  . jav  a 2  s  .  co  m*/
 * @param htmlContent
 * @param title
 * @param workItemID
 * @param personID
 * @param imageCaptionMap
 * @return
 */
private static List<Object> transformHTMLContent(WordprocessingMLPackage wordMLPackage, String htmlContent,
        String title, Integer workItemID, Integer personID, Map<String, ImageOrTableCaption> imageCaptionMap,
        Map<String, ImageOrTableCaption> tableCaptionMap, PreprocessImage preprocessImage,
        PreprocessTable preprocessTable) {
    //HTML processor libraries are used:
    //1. jsoup: cleans up the HTML fragment, knows HTML5 (figure and figurecaption is pre-processed) but the resulted HTML is not usable by XHTMLImporterImpl
    //2. tidy: throws away HTML5 tags (anyway removed previously in jsoup pre-processing) and produces usable input for XHTMLImporterImpl
    List<Object> contents = null;
    if (htmlContent != null && htmlContent.length() > 0) {
        String jsoupContent = preprocessImage.preprocessImages(htmlContent, personID, imageCaptionMap);
        jsoupContent = preprocessTable.prepocessTableCaption(jsoupContent, tableCaptionMap);
        //jsoup does not prepare the HTML usable by XHTMLImporterImpl so we use tidy for that (tidy throws away HTML5 tags so figure and figurecaption would be removed)
        Tidy tidy = new Tidy(); //obtain a new Tidy instance
        tidy.setXHTML(true); //set desired config options using tidy setters
        InputStream inputStream = null;
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try {
            inputStream = new ByteArrayInputStream(jsoupContent.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e1) {
            LOGGER.warn("UnsupportedEncodingException " + e1.getMessage());
        }
        try {
            tidy.parse(inputStream, outputStream); // run tidy, providing an input and output stream
        } catch (Exception e) {
            LOGGER.error("Tidy parsing the xhtml content for item " + workItemID + " with title " + title
                    + " failed with " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
        try {
            jsoupContent = outputStream.toString("UTF-8");
        } catch (UnsupportedEncodingException e1) {
            LOGGER.debug(e1);
        }
        if (jsoupContent != null && jsoupContent.length() > 0) {
            try {
                XHTMLImporterImpl xhtmlImporter = new XHTMLImporterImpl(wordMLPackage);
                contents = xhtmlImporter.convert(jsoupContent, null);
            } catch (Docx4JException e) {
                LOGGER.error("Converting the xhtml content for item " + workItemID + " with title " + title
                        + " failed with " + e.getMessage());
                LOGGER.debug(ExceptionUtils.getStackTrace(e));
            }
        }
    }
    return contents;
}

From source file:com.silverpeas.gallery.MediaHelper.java

public static void setMetaData(final FileHandler fileHandler, final Photo photo, final String lang)
        throws MediaMetadataException, IOException {
    if (MediaMimeType.JPG == photo.getFileMimeType()) {
        final HandledFile handledFile = fileHandler.getHandledFile(Media.BASE_PATH, photo.getInstanceId(),
                photo.getWorkspaceSubFolderName(), photo.getFileName());
        if (handledFile.exists()) {
            try {
                final MediaMetadataExtractor extractor = new DrewMediaMetadataExtractor(photo.getInstanceId());
                for (final MetaData meta : extractor.extractImageExifMetaData(handledFile.getFile(), lang)) {
                    photo.addMetaData(meta);
                }//from  ww  w.j av a  2 s .co  m
                for (final MetaData meta : extractor.extractImageIptcMetaData(handledFile.getFile(), lang)) {
                    photo.addMetaData(meta);
                }
            } catch (UnsupportedEncodingException e) {
                SilverTrace.error("gallery", "MediaHelper.computeWatermarkText", "root.MSG_BAD_ENCODING",
                        "Bad metadata encoding in image " + photo.getTitle() + ": " + e.getMessage());
            }
        }
    }
}

From source file:jef.tools.security.EncrypterUtil.java

public static String decryptString(byte[] data, SecretKey key, String charset) {
    try {//from ww w .  j  a va  2  s.  c om
        if (charset == null) {
            return new String(decrypt(data, key));
        } else {
            return new String(decrypt(data, key), charset);
        }
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}

From source file:egovframework.asadal.asapro.com.cmm.util.AsaproEgovStringUtil.java

License:asdf

/**
 * ??  ?(EUC-KR[KSC5601],UTF-8..)?  ?    ?? ??
 * ? ?  String temp = new String(?.getBytes(" ?")," ?");
 * String temp = new String(?.getBytes("8859_1"),"KSC5601"); => UTF-8 ?
 * EUC-KR/*from  w  w  w.  java  2 s .  c om*/
 *
 * @param srcString
 *            - ?
 * @param srcCharsetNm
 *            - ? CharsetNm
 * @param charsetNm
 *            - CharsetNm
 * @return ?() ?
 * @exception MyException
 * @see
 */
public static String getEncdDcd(String srcString, String srcCharsetNm, String cnvrCharsetNm) {

    String rtnStr = null;

    if (srcString == null)
        return null;

    try {
        rtnStr = new String(srcString.getBytes(srcCharsetNm), cnvrCharsetNm);
    } catch (UnsupportedEncodingException e) {
        log.debug(e.getMessage());
    }

    return rtnStr;
}

From source file:acp.sdk.SecureUtil.java

/**
 * md5?16?//from w  w w  .j  a  va 2s  .  c om
 * 
 * @param datas
 *            ?
 * @param encoding
 *            ?
 * @return 
 */
public static byte[] md5X16(String datas, String encoding) {
    byte[] bytes = md5(datas, encoding);
    StringBuilder md5StrBuff = new StringBuilder();
    for (int i = 0; i < bytes.length; i++) {
        if (Integer.toHexString(0xFF & bytes[i]).length() == 1) {
            md5StrBuff.append("0").append(Integer.toHexString(0xFF & bytes[i]));
        } else {
            md5StrBuff.append(Integer.toHexString(0xFF & bytes[i]));
        }
    }
    try {
        return md5StrBuff.toString().getBytes(encoding);
    } catch (UnsupportedEncodingException e) {
        LogUtil.writeErrorLog(e.getMessage(), e);
        return null;
    }
}

From source file:acp.sdk.SecureUtil.java

/**
 * sha1?16?/*  w ww.  j av a2 s .  com*/
 * 
 * @param data
 *            ?
 * @param encoding
 *            ?
 * @return 
 */
public static byte[] sha1X16(String data, String encoding) {
    byte[] bytes = sha1(data, encoding);
    StringBuilder sha1StrBuff = new StringBuilder();
    for (int i = 0; i < bytes.length; i++) {
        if (Integer.toHexString(0xFF & bytes[i]).length() == 1) {
            sha1StrBuff.append("0").append(Integer.toHexString(0xFF & bytes[i]));
        } else {
            sha1StrBuff.append(Integer.toHexString(0xFF & bytes[i]));
        }
    }
    try {
        return sha1StrBuff.toString().getBytes(encoding);
    } catch (UnsupportedEncodingException e) {
        LogUtil.writeErrorLog(e.getMessage(), e);
        return null;
    }
}