public class Charsets extends Object
Every implementation of the Java platform is required to support the following character encodings. Consult the release documentation for your implementation to see if any other encodings are supported. Consult the release documentation for your implementation to see if any other encodings are supported.
US-ASCIIISO-8859-1UTF-8UTF-16BEUTF-16LEUTF-16| Modifier and Type | Method and Description |
|---|---|
static boolean |
isAlias(Charset charset,
String charsetName)
Tests whether the given non-null Charset has an alias of the given name.
|
static boolean |
isUTF8(Charset charset)
Tests whether a given encoding is UTF-8.
|
static SortedMap<String,Charset> |
requiredCharsets()
Constructs a sorted map from canonical charset names to charset objects required of every implementation of the
Java platform.
|
static Charset |
toCharset(Charset charset)
Returns the given Charset or the
default Charset if the given Charset is null. |
static Charset |
toCharset(Charset charset,
Charset defaultCharset)
Returns the given charset if non-null, otherwise return defaultCharset.
|
static Charset |
toCharset(String charsetName)
Returns a Charset for the named charset.
|
static Charset |
toCharset(String charsetName,
Charset defaultCharset)
Returns a Charset for the named charset.
|
static Charset |
toCharsetDefault(String charsetName,
Charset defaultCharset)
Returns a Charset for the named charset or the
defaultCharset. |
public static boolean isAlias(Charset charset, String charsetName)
charset - a non-null Charset.charsetName - The name to test.public static boolean isUTF8(Charset charset)
charset - If the given charset is null, then check the platform's default encoding.public static SortedMap<String,Charset> requiredCharsets()
From the Java documentation Standard charsets:
Charset.availableCharsets()public static Charset toCharset(Charset charset)
default Charset if the given Charset is null.charset - A charset or null.Charset.defaultCharset()public static Charset toCharset(Charset charset, Charset defaultCharset)
charset - The charset to test, may be null.defaultCharset - The charset to return if charset is null, may be null.public static Charset toCharset(String charsetName) throws UnsupportedCharsetException
default Charset.charsetName - The name of the requested charset, may be null.UnsupportedCharsetException - If the named charset is unavailable (unchecked exception).Charset.defaultCharset()public static Charset toCharset(String charsetName, Charset defaultCharset) throws UnsupportedCharsetException
charsetName - The name of the requested charset, may be null.defaultCharset - The charset to return if charsetName is null, may be null.UnsupportedCharsetException - If the named charset is unavailable (unchecked exception).public static Charset toCharsetDefault(String charsetName, Charset defaultCharset)
defaultCharset.
If charsetName cannot load a charset, return defaultCharset. Therefore, this method should never fail and always return a Charset.
charsetName - The name of the requested charset, may be null.defaultCharset - The charset to return if charsetName is null or there is a problem, may be null which returns Charset.defaultCharset().defaultCharset if any errors occur.Charset.defaultCharset()