Java Code Examples for java.nio.charset.Charset.displayName()

The following are Jave code examples for showing how to use displayName() of the java.nio.charset.Charset class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: AbstractMatcher.java   View Source Code Vote up 5 votes
/**
 * Handle an error thrown while file decoding. Inform search listener and
 * append detailed info into the IDE Log.
 */
protected final void handleDecodingError(SearchListener listener,
        FileObject file, CharsetDecoder decoder,
        CharacterCodingException e) {

    String charsetName;
    try {
        if (decoder.isAutoDetecting() && decoder.isCharsetDetected()) {
            Charset c = decoder.detectedCharset();
            if (c != null) {
                charsetName = c.displayName();
            } else {
                charsetName = decoder.charset().displayName();
            }
        } else {
            charsetName = decoder.charset().displayName();
        }
    } catch (Exception ex) {
        LOG.log(Level.INFO, "Failed to obtain actual charset", ex); //NOI18N
        charsetName = decoder == null ? "null" : decoder.toString();//NOI18N
    }

    String msg = NbBundle.getMessage(ResultView.class,
            "TEXT_INFO_ERROR_ENCODING", charsetName);               //NOI18N
    listener.fileContentMatchingError(file.getPath(),
            new Exception(msg, e));
    LOG.log(Level.INFO, "{0}; UnmappableCharacterException: {1}", //NOI18N
            new Object[]{file.getPath(), e.getMessage()});
}
 
Example 2
Project: cyberduck   File: DefaultCharsetProvider.java   View Source Code Vote up 5 votes
@Override
public String[] availableCharsets() {
    List<String> charsets = new Collection<String>();
    for(Charset charset : Charset.availableCharsets().values()) {
        final String name = charset.displayName();
        if(!(name.startsWith("IBM") || ((name.startsWith("x-") && !name.startsWith("x-Mac"))))) {
            charsets.add(name);
        }
    }
    return charsets.toArray(new String[charsets.size()]);
}
 
Example 3
Project: fastcrawler   File: Page.java   View Source Code Vote up 5 votes
/**
 * load the content of this page from a fetched HttpEntity.
 * @param entity HttpEntity
 * @param maxBytes The maximum number of bytes to read
 * @throws Exception when load fails
 */
public void load(HttpEntity entity, int maxBytes) throws Exception {
    contentType = null;
    Header type = entity.getContentType();
    if (type != null) {
        contentType = type.getValue();
    }
    contentEncoding = null;
    Header encoding = entity.getContentEncoding();
    if (encoding != null) {
        contentEncoding = encoding.getValue();
    }

    Charset charset = ContentType.getOrDefault(entity).getCharset();
    if (charset != null) {
        contentCharset = charset.displayName();
    }else {
        contentCharset = Charset.defaultCharset().displayName();
    }

    contentData = toByteArray(entity, maxBytes);
}