Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public class Charset
- Object
- Charset
ImplementsComparable<Charset>
A named character encoding. This runtime has the three charsets every
Java platform must: UTF-8, US-ASCII and ISO-8859-1, under their canonical
names and the JDK’s aliases. Encoding and decoding go through the
String constructors and
getBytes that take a Charset, and the readers
and writers of java.io.Constructors
protected Charset(String canonicalName, String[] aliases) |
Methods
public final int compareTo(Charset another) | Compares canonical names, ignoring case. |
public final String name() | The canonical name. |
public String displayName() | The canonical name. |
public String displayName(Locale locale) | The canonical name, whatever the locale. |
public final Set<String> aliases() | The aliases of the charset. |
public final boolean isRegistered() | Whether the charset is registered with IANA: the three this runtime has are, and a name with the reserved X- prefix never is. |
public boolean canEncode() | Whether the charset can encode; the three this runtime has can. |
public final boolean equals(Object obj) | Whether obj is a charset of the same canonical name. |
public final int hashCode() | The hash of the canonical name. |
public final String toString() | The canonical name. |
public static Charset defaultCharset() | UTF-8, the default charset of this runtime on every platform. |
public static boolean isSupported(String charsetName) | Whether charsetName names a charset this runtime has. |
public static Charset forName(String charsetName) | The charset charsetName names, by canonical name or alias, in any case. |
public static Charset forName(String charsetName, Charset fallback) | The charset charsetName names, or fallback when the name is illegal or names a charset this runtime does not have. |
Inherited methods
Constructor details
Charset
protected Charset(String canonicalName, String[] aliases)Method details
compareTo
public final int compareTo(Charset another)Compares canonical names, ignoring case.
Parameters
anotherCharset- the object to compare to this instance.
Returns
a negative integer if this instance is less than
another;
a positive integer if this instance is greater than
another; 0 if this instance has the same order as
another.Throws
ClassCastException- if
anothercannot be converted into something comparable tothisinstance.
name
public final String name()The canonical name.
displayName
public String displayName()The canonical name.
displayName
public String displayName(Locale locale)The canonical name, whatever the locale.
aliases
public final Set<String> aliases()The aliases of the charset.
isRegistered
public final boolean isRegistered()Whether the charset is registered with IANA: the three this runtime
has are, and a name with the reserved
X- prefix never is.canEncode
public boolean canEncode()Whether the charset can encode; the three this runtime has can.
equals
public final boolean equals(Object obj)Whether
obj is a charset of the same canonical name.hashCode
public final int hashCode()The hash of the canonical name.
toString
public final String toString()The canonical name.
defaultCharset
public static Charset defaultCharset()UTF-8, the default charset of this runtime on every platform.
isSupported
public static boolean isSupported(String charsetName)Whether
charsetName names a charset this runtime has.Throws
IllegalCharsetNameException- if the name is not a legal charset name
IllegalArgumentException- if it is null
forName
public static Charset forName(String charsetName)The charset
charsetName names, by canonical name or alias, in any
case.Throws
IllegalCharsetNameException- if the name is not a legal charset name
UnsupportedCharsetException- if this runtime has no such charset
IllegalArgumentException- if it is null
forName
public static Charset forName(String charsetName, Charset fallback)The charset
charsetName names, or fallback when the name is
illegal or names a charset this runtime does not have.