當前位置: 首頁>>代碼示例>>Java>>正文


Java UnsupportedCharsetException.getMessage方法代碼示例

本文整理匯總了Java中java.nio.charset.UnsupportedCharsetException.getMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java UnsupportedCharsetException.getMessage方法的具體用法?Java UnsupportedCharsetException.getMessage怎麽用?Java UnsupportedCharsetException.getMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.charset.UnsupportedCharsetException的用法示例。


在下文中一共展示了UnsupportedCharsetException.getMessage方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toString

import java.nio.charset.UnsupportedCharsetException; //導入方法依賴的package包/類
/**
 * Get the entity content as a String, using the provided default character set
 * if none is found in the entity.
 * If defaultCharset is null, the default "ISO-8859-1" is used.
 *
 * @param entity must not be null
 * @param defaultCharset character set to be applied if none found in the entity,
 * or if the entity provided charset is invalid or not available.
 * @return the entity content as a String. May be null if
 *   {@link HttpEntity#getContent()} is null.
 * @throws ParseException if header elements cannot be parsed
 * @throws IllegalArgumentException if entity is null or if content length > Integer.MAX_VALUE
 * @throws IOException if an error occurs reading the input stream
 * @throws java.nio.charset.UnsupportedCharsetException Thrown when the named entity's charset is not available in
 * this instance of the Java virtual machine and no defaultCharset is provided.
 */
public static String toString(
        final HttpEntity entity, final Charset defaultCharset) throws IOException, ParseException {
    Args.notNull(entity, "Entity");
    ContentType contentType = null;
    try {
        contentType = ContentType.get(entity);
    } catch (final UnsupportedCharsetException ex) {
        if (defaultCharset == null) {
            throw new UnsupportedEncodingException(ex.getMessage());
        }
    }
    if (contentType != null) {
        if (contentType.getCharset() == null) {
            contentType = contentType.withCharset(defaultCharset);
        }
    } else {
        contentType = ContentType.DEFAULT_TEXT.withCharset(defaultCharset);
    }
    return toString(entity, contentType);
}
 
開發者ID:gusavila92,項目名稱:java-android-websocket-client,代碼行數:37,代碼來源:EntityUtils.java

示例2: toString

import java.nio.charset.UnsupportedCharsetException; //導入方法依賴的package包/類
/**
 * Get the entity content as a String, using the provided default character set
 * if none is found in the entity.
 * If defaultCharset is null, the default "ISO-8859-1" is used.
 *
 * @param entity must not be null
 * @param defaultCharset character set to be applied if none found in the entity,
 * or if the entity provided charset is invalid or not available.
 * @return the entity content as a String. May be null if
 *   {@link HttpEntity#getContent()} is null.
 * @throws ParseException if header elements cannot be parsed
 * @throws IllegalArgumentException if entity is null or if content length > Integer.MAX_VALUE
 * @throws IOException if an error occurs reading the input stream
 * @throws java.nio.charset.UnsupportedCharsetException Thrown when the named entity's charset is not available in
 * this instance of the Java virtual machine and no defaultCharset is provided.
 */
public static String toString(
        final HttpEntity entity, final Charset defaultCharset) throws IOException, ParseException {
    Args.notNull(entity, "Entity");
    ru.radiomayak.http.entity.ContentType contentType = null;
    try {
        contentType = ru.radiomayak.http.entity.ContentType.get(entity);
    } catch (final UnsupportedCharsetException ex) {
        if (defaultCharset == null) {
            throw new UnsupportedEncodingException(ex.getMessage());
        }
    }
    if (contentType != null) {
        if (contentType.getCharset() == null) {
            contentType = contentType.withCharset(defaultCharset);
        }
    } else {
        contentType = ru.radiomayak.http.entity.ContentType.DEFAULT_TEXT.withCharset(defaultCharset);
    }
    return toString(entity, contentType);
}
 
開發者ID:kalikov,項目名稱:lighthouse,代碼行數:37,代碼來源:EntityUtils.java

示例3: toString

import java.nio.charset.UnsupportedCharsetException; //導入方法依賴的package包/類
/**
 * Get the entity content as a String, using the provided default character set
 * if none is found in the entity.
 * If defaultCharset is null, the default "ISO-8859-1" is used.
 *
 * @param entity must not be null
 * @param defaultCharset character set to be applied if none found in the entity
 * @return the entity content as a String. May be null if
 *   {@link HttpEntity#getContent()} is null.
 * @throws ParseException if header elements cannot be parsed
 * @throws IllegalArgumentException if entity is null or if content length > Integer.MAX_VALUE
 * @throws IOException if an error occurs reading the input stream
 * @throws UnsupportedCharsetException Thrown when the named charset is not available in
 * this instance of the Java virtual machine
 */
public static String toString(
        final HttpEntity entity, final Charset defaultCharset) throws IOException, ParseException {
    Args.notNull(entity, "Entity");
    final InputStream instream = entity.getContent();
    if (instream == null) {
        return null;
    }
    try {
        Args.check(entity.getContentLength() <= Integer.MAX_VALUE,
                "HTTP entity too large to be buffered in memory");
        int i = (int)entity.getContentLength();
        if (i < 0) {
            i = 4096;
        }
        Charset charset = null;
        try {
            final ContentType contentType = ContentType.get(entity);
            if (contentType != null) {
                charset = contentType.getCharset();
            }
        } catch (final UnsupportedCharsetException ex) {
            throw new UnsupportedEncodingException(ex.getMessage());
        }
        if (charset == null) {
            charset = defaultCharset;
        }
        if (charset == null) {
            charset = HTTP.DEF_CONTENT_CHARSET;
        }
        final Reader reader = new InputStreamReader(instream, charset);
        final CharArrayBuffer buffer = new CharArrayBuffer(i);
        final char[] tmp = new char[1024];
        int l;
        while((l = reader.read(tmp)) != -1) {
            buffer.append(tmp, 0, l);
        }
        return buffer.toString();
    } finally {
        instream.close();
    }
}
 
開發者ID:mozilla-mobile,項目名稱:FirefoxData-android,代碼行數:57,代碼來源:EntityUtils.java


注:本文中的java.nio.charset.UnsupportedCharsetException.getMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。