当前位置: 首页>>代码示例>>Java>>正文


Java UnsupportedCharsetException类代码示例

本文整理汇总了Java中java.nio.charset.UnsupportedCharsetException的典型用法代码示例。如果您正苦于以下问题:Java UnsupportedCharsetException类的具体用法?Java UnsupportedCharsetException怎么用?Java UnsupportedCharsetException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UnsupportedCharsetException类属于java.nio.charset包,在下文中一共展示了UnsupportedCharsetException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCharset

import java.nio.charset.UnsupportedCharsetException; //导入依赖的package包/类
private static Charset getCharset(String contentType) {
    // FIXME the spec default is ISO-8859-1
    Charset encoding = Charset.forName("UTF-8"); // NOI18N
    if (contentType != null) {
        String[] parts = contentType.trim().split(";"); // NOI18N
        for (String p : parts) {
            String upper = p.toUpperCase(Locale.ENGLISH);
            if (upper.startsWith("CHARSET")) { // NOI18N
                int index = upper.indexOf("=", 7); // NOI18N
                if (index > 0 && index < upper.length() -1) {
                    try {
                        encoding = Charset.forName(upper.substring(index + 1).trim());
                    } catch (UnsupportedCharsetException ex) {
                        // noop using the UTF-8
                    }
                }
                break;
            }
        }
    }
    return encoding;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:HttpUtils.java

示例2: Impl

import java.nio.charset.UnsupportedCharsetException; //导入依赖的package包/类
Impl(String name, String title, String MIMEType, Reader r) {
    this.name = name;
    this.title = title;
    this.MIMEType = MIMEType;
    this.r = r;
    this.readerSource = null;
    this.w = null;
    this.file = null;
    if (r instanceof InputStreamReader) {
        try {
            encoding = Charset.forName(((InputStreamReader) r).getEncoding());
        } catch (UnsupportedCharsetException e) {
            // ignore, encoding will be null
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:StreamSource.java

示例3: sendLogResponse

import java.nio.charset.UnsupportedCharsetException; //导入依赖的package包/类
/**
 * 开始解析服务器返回参数
 */
private void sendLogResponse(Response response) throws IOException {
    String rBody = "";
    if (response != null && response.body() != null) {
        BufferedSource source = response.body().source();
        source.request(Long.MAX_VALUE); // Buffer the entire body.
        Buffer buffer = source.buffer();

        Charset charset = Charset.forName("UTF-8");
        MediaType contentType = response.body().contentType();
        if (contentType != null) {
            try {
                charset = contentType.charset(Charset.forName("UTF-8"));
            } catch (UnsupportedCharsetException e) {
                e.printStackTrace();
            }
        }
        rBody = buffer.clone().readString(charset);
    }
    LogUtils.i("接收:" + rBody.toString());
}
 
开发者ID:JJS-CN,项目名称:JBase,代码行数:24,代码来源:BaseInterceptor.java

示例4: findCharset

import java.nio.charset.UnsupportedCharsetException; //导入依赖的package包/类
static Charset findCharset(String alias) throws UnsupportedEncodingException {
    try {
        Charset cs = charsetsByAlias.get(alias);

        if (cs == null) {
            cs = Charset.forName(alias);
            Charset oldCs = charsetsByAlias.putIfAbsent(alias, cs);
            if (oldCs != null) {
                // if the previous value was recently set by another thread we return it instead of value we found here
                cs = oldCs;
            }
        }

        return cs;

        // We re-throw these runtimes for compatibility with java.io
    } catch (UnsupportedCharsetException uce) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalCharsetNameException icne) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalArgumentException iae) {
        throw new UnsupportedEncodingException(alias);
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:25,代码来源:StringUtils.java

示例5: findCharset

import java.nio.charset.UnsupportedCharsetException; //导入依赖的package包/类
static Charset findCharset(String alias) throws UnsupportedEncodingException {
    try {
        Charset cs = charsetsByAlias.get(alias);

        if (cs == null) {
            cs = Charset.forName(alias);
            charsetsByAlias.putIfAbsent(alias, cs);
        }

        return cs;

        // We re-throw these runtimes for compatibility with java.io
    } catch (UnsupportedCharsetException uce) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalCharsetNameException icne) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalArgumentException iae) {
        throw new UnsupportedEncodingException(alias);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:StringUtils.java

示例6: setCharacterEncoding

import java.nio.charset.UnsupportedCharsetException; //导入依赖的package包/类
@Override
public void setCharacterEncoding(final String env) throws UnsupportedEncodingException {
    if (readStarted) {
        return;
    }
    try {
        characterEncoding = Charset.forName(env);

        final ManagedServlet originalServlet = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY).getOriginalServletPathMatch().getServletChain().getManagedServlet();
        final FormDataParser parser = originalServlet.getFormParserFactory().createParser(exchange);
        if (parser != null) {
            parser.setCharacterEncoding(env);
        }
    } catch (UnsupportedCharsetException e) {
        throw new UnsupportedEncodingException();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:HttpServletRequestImpl.java

示例7: 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 &gt; 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

示例8: StringEntity

import java.nio.charset.UnsupportedCharsetException; //导入依赖的package包/类
/**
 * Creates a StringEntity with the specified content and content type.
 *
 * @param string content to be used. Not {@code null}.
 * @param contentType content type to be used. May be {@code null}, in which case the default
 *   MIME type {@link ContentType#TEXT_PLAIN} is assumed.
 *
 * @throws IllegalArgumentException if the string parameter is null
 * @throws UnsupportedCharsetException Thrown when the named charset is not available in
 * this instance of the Java virtual machine
 * @since 4.2
 */
public StringEntity(final String string, final ContentType contentType) throws UnsupportedCharsetException {
    super();
    Args.notNull(string, "Source string");
    Charset charset = contentType != null ? contentType.getCharset() : null;
    if (charset == null) {
        charset = HTTP.DEF_CONTENT_CHARSET;
    }
    try {
        this.content = string.getBytes(charset.name());
    } catch (final UnsupportedEncodingException ex) {
        // should never happen
        throw new UnsupportedCharsetException(charset.name());
    }
    if (contentType != null) {
        setContentType(contentType.toString());
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:30,代码来源:StringEntity.java

示例9: intercept

import java.nio.charset.UnsupportedCharsetException; //导入依赖的package包/类
@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    Response response = chain.proceed(request);
    ResponseBody body = response.body();
    long length = body.contentLength();
    BufferedSource source = body.source();
    source.request(Long.MAX_VALUE);
    Buffer buffer = source.buffer();
    Charset charset = Charset.forName("UTF-8");
    MediaType type = body.contentType();
    if (type != null) {
        try {
            charset = type.charset(charset);
        } catch (UnsupportedCharsetException e) {
            e.printStackTrace();
            return response;
        }
    }
    if (length != 0) {
        System.out.println("shenhua sout:--------------------------------------------开始打印返回数据----------------------------------------------------");
        System.out.println("shenhua sout:" + buffer.clone().readString(charset));
    }
    return response;
}
 
开发者ID:shenhuanet,项目名称:OpenEyesReading-android,代码行数:26,代码来源:RetrofitManager.java

示例10: JavaCTBConverter

import java.nio.charset.UnsupportedCharsetException; //导入依赖的package包/类
public JavaCTBConverter(OSFCodeSetRegistry.Entry codeset,
                        int alignmentForEncoding) {

    try {
        ctb = cache.getCharToByteConverter(codeset.getName());
        if (ctb == null) {
            Charset tmpCharset = Charset.forName(codeset.getName());
            ctb = tmpCharset.newEncoder();
            cache.setConverter(codeset.getName(), ctb);
        }
    } catch(IllegalCharsetNameException icne) {

        // This can only happen if one of our Entries has
        // an invalid name.
        throw wrapper.invalidCtbConverterName(icne,codeset.getName());
    } catch(UnsupportedCharsetException ucne) {

        // This can only happen if one of our Entries has
        // an unsupported name.
        throw wrapper.invalidCtbConverterName(ucne,codeset.getName());
    }

    this.codeset = codeset;
    alignment = alignmentForEncoding;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:CodeSetConversion.java

示例11: detectCharsetImpl

import java.nio.charset.UnsupportedCharsetException; //导入依赖的package包/类
@Override
protected Charset detectCharsetImpl(byte[] buffer) throws Exception
{
    CharsetDetector detector = new CharsetDetector();
    detector.setText(buffer);
    CharsetMatch match = detector.detect();

    if(match != null && match.getConfidence() > threshold)
    {
        try
        {
            return Charset.forName(match.getName());
        }
        catch(UnsupportedCharsetException e)
        {
            logger.info("Charset detected as " + match.getName() + " but the JVM does not support this, detection skipped");
        }
    }
    return null;
}
 
开发者ID:Alfresco,项目名称:alfresco-data-model,代码行数:21,代码来源:TikaCharsetFinder.java

示例12: create

import java.nio.charset.UnsupportedCharsetException; //导入依赖的package包/类
private static ContentType create(final String mimeType, final NameValuePair[] params, final boolean strict) {
    Charset charset = null;
    for (final NameValuePair param: params) {
        if (param.getName().equalsIgnoreCase("charset")) {
            final String s = param.getValue();
            if (!TextUtils.isBlank(s)) {
                try {
                    charset =  Charset.forName(s);
                } catch (final UnsupportedCharsetException ex) {
                    if (strict) {
                        throw ex;
                    }
                }
            }
            break;
        }
    }
    return new ContentType(mimeType, charset, params != null && params.length > 0 ? params : null);
}
 
开发者ID:gusavila92,项目名称:java-android-websocket-client,代码行数:20,代码来源:ContentType.java

示例13: 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 &gt; 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

示例14: bomStream

import java.nio.charset.UnsupportedCharsetException; //导入依赖的package包/类
/**
 * Convert stream to ByteArrayInputStream by given character set.
 * @param charset target character set.
 * @param file a file that contains no BOM head content.
 * @return a ByteArrayInputStream contains BOM heads and bytes in original
 *         stream
 * @throws IOException I/O operation failed or unsupported character set.
 */
public static InputStream bomStream(String charset, String file)
        throws IOException {
    String localCharset = charset;
    if (charset.equals("UTF-16") || charset.equals("UTF-32")) {
        localCharset
            += ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN ? "BE" : "LE";
    }
    if (!bom.containsKey(localCharset))
        throw new UnsupportedCharsetException("Charset:" + localCharset);

    byte[] content = Files.readAllLines(Paths.get(file)).stream().
            collect(Collectors.joining()).getBytes(localCharset);
    byte[] head = bom.get(localCharset);
    ByteBuffer bb = ByteBuffer.allocate(content.length + head.length);
    bb.put(head);
    bb.put(content);
    return new ByteArrayInputStream(bb.array());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:JAXPTestUtilities.java

示例15: setOutput

import java.nio.charset.UnsupportedCharsetException; //导入依赖的package包/类
public void setOutput(OutputStream os, String encoding)
        throws IOException, IllegalArgumentException, IllegalStateException {
    if (os == null) {
        throw new IllegalArgumentException();
    }
    try {
        charset = Charset.forName(encoding).newEncoder();
    } catch (IllegalCharsetNameException | UnsupportedCharsetException e) {
        throw (UnsupportedEncodingException) (new UnsupportedEncodingException(encoding).initCause(e));
    }
    out = os;
}
 
开发者ID:Doist,项目名称:JobSchedulerCompat,代码行数:13,代码来源:XmlUtils.java


注:本文中的java.nio.charset.UnsupportedCharsetException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。