Android Charset Get 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>();

    /**//w  w  w  .  j  av  a 2s.  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. getLocaleCharset(String locale)
  2. isCharsetSupported()