Example usage for java.nio.charset Charset displayName

List of usage examples for java.nio.charset Charset displayName

Introduction

In this page you can find the example usage for java.nio.charset Charset displayName.

Prototype

public String displayName(Locale locale) 

Source Link

Document

Returns this charset's human-readable name for the given locale.

Usage

From source file:Main.java

public static void main(String[] args) {
    Map<String, Charset> charsets = Charset.availableCharsets();
    Iterator<Charset> iterator = charsets.values().iterator();
    while (iterator.hasNext()) {
        Charset cs = (Charset) iterator.next();
        System.out.print(cs.displayName(Locale.getDefault()));
    }//ww w .  j ava 2 s .  com
}

From source file:com.microsoft.tfs.core.util.FileEncoding.java

/**
 * Gets a pretty name to display to the user for this encoding. If no name
 * for the encoding can be found, the encoding's code page will simply be
 * returned as a string./*from ww  w .  j  av  a 2s .c  o  m*/
 *
 * @param locale
 *        the locale to use when finding localized encoding names (not
 *        null).
 * @return the fancy string name of the given encoding (e.g. "utf-8"), or
 *         simply the code page number formatted as string if the name was
 *         not found (e.g. "1253").
 */
public String getName(final Locale locale) {
    Check.notNull(locale, "locale"); //$NON-NLS-1$

    if (equals(BINARY)) {
        return "binary"; //$NON-NLS-1$
    } else if (equals(AUTOMATICALLY_DETECT)) {
        return "auto"; //$NON-NLS-1$
    } else if (equals(DEFAULT_TEXT)) {
        return "text"; //$NON-NLS-1$
    } else {
        final Charset c = CodePageMapping.getCharset(tfsCodePage, false);

        if (c != null) {
            return c.displayName(locale);
        }
    }

    return toString();
}

From source file:com.github.hateoas.forms.spring.xhtml.XhtmlResourceMessageConverter.java

@Override
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage)
        throws IOException, HttpMessageNotReadableException {

    InputStream is;//from www. ja  va2s  . c  o m
    if (inputMessage instanceof ServletServerHttpRequest) {
        // this is necessary to support HiddenHttpMethodFilter
        // thanks to https://www.w3.org/html/wg/tracker/issues/195
        // but see http://dev.w3.org/html5/decision-policy/html5-2014-plan.html#issues
        // and http://cameronjones.github.io/form-http-extensions/index.html
        // and http://www.w3.org/TR/form-http-extensions/
        // TODO recognize this more safely or make the filter mandatory
        MediaType contentType = inputMessage.getHeaders().getContentType();
        Charset charset = contentType.getCharSet() != null ? contentType.getCharSet() : this.charset;
        ServletServerHttpRequest servletServerHttpRequest = (ServletServerHttpRequest) inputMessage;
        HttpServletRequest servletRequest = servletServerHttpRequest.getServletRequest();
        is = getBodyFromServletRequestParameters(servletRequest, charset.displayName(Locale.US));
    } else {
        is = inputMessage.getBody();
    }
    return readRequestBody(clazz, is, charset);
}

From source file:com.sonicle.webtop.core.Service.java

public void processLookupTextEncodings(HttpServletRequest request, HttpServletResponse response,
        PrintWriter out) {/*from w  w  w.j  ava  2 s .  co  m*/
    ArrayList<JsSimple> items = new ArrayList<>();

    try {
        SortedMap<String, Charset> charsets = Charset.availableCharsets();
        for (Charset charset : charsets.values()) {
            if (!charset.canEncode())
                continue;
            items.add(new JsSimple(charset.name(), charset.displayName(Locale.ENGLISH)));
        }
        new JsonResult("encodings", items, items.size()).printTo(out);

    } catch (Exception ex) {
        logger.error("Error in LookupTextEncodings", ex);
        new JsonResult(false, "Unable to lookup available text encodings").printTo(out);
    }
}

From source file:org.polymap.p4.data.importer.prompts.CharsetPrompt.java

private String displayName(Charset charset) {
    StringBuffer name = new StringBuffer(charset.displayName(Polymap.getSessionLocale()));
    if (!charset.aliases().isEmpty()) {
        name.append(" ( ");
        StringJoiner joiner = new StringJoiner(", ");
        for (String alias : charset.aliases()) {
            joiner.add(alias);//from  www. j a  v  a 2 s .c o m
        }
        name.append(joiner.toString());
        name.append(" )");
    }
    return name.toString();
}