Java Charset Create getCharset(String enc)

Here you can find the source of getCharset(String enc)

Description

Returns the Java Charset that should be used for the provided encoding

License

Open Source License

Declaration

public static Charset getCharset(String enc) 

Method Source Code

//package com.java2s;

import java.nio.charset.Charset;

import java.util.concurrent.ConcurrentHashMap;

public class Main {
    private static final ConcurrentHashMap<String, Charset> encodingToCharsetCache = new ConcurrentHashMap<String, Charset>();

    /**/*from   w  w  w  .  ja  va  2 s  .co  m*/
     * Returns the Java Charset that should be used for the provided encoding
     */
    public static Charset getCharset(String enc) {
        Charset charset = encodingToCharsetCache.get(enc);
        if (charset == null) {
            charset = Charset.forName(enc);
            encodingToCharsetCache.put(enc, charset);
        }
        return charset;
    }
}

Related

  1. getCharset(int ibmCharacterSetId)
  2. getCharSet(String charset)
  3. getCharset(String charsetName)
  4. getCharset(String charsetName)
  5. getCharset(String contentType)
  6. getCharset(String encoding)
  7. getCharset(String encoding)
  8. getCharset(String name)
  9. getCharsetForSortOrder(final int sortOrder)