Class Charset
java.lang.Object
java.nio.charset.Charset
- All Implemented Interfaces:
Comparable<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.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaliases()The aliases of the charset.booleanWhether the charset can encode; the three this runtime has can.final intCompares canonical names, ignoring case.static CharsetUTF-8, the default charset of this runtime on every platform.The canonical name.displayName(Locale locale) The canonical name, whatever the locale.final booleanWhetherobjis a charset of the same canonical name.static CharsetThe charsetcharsetNamenames, by canonical name or alias, in any case.static CharsetThe charsetcharsetNamenames, orfallbackwhen the name is illegal or names a charset this runtime does not have.final inthashCode()The hash of the canonical name.final booleanWhether the charset is registered with IANA: the three this runtime has are, and a name with the reservedX-prefix never is.static booleanisSupported(String charsetName) WhethercharsetNamenames a charset this runtime has.final Stringname()The canonical name.final StringtoString()The canonical name.
-
Constructor Details
-
Charset
-
-
Method Details
-
compareTo
Compares canonical names, ignoring case.- Specified by:
compareToin interfaceComparable<Charset>- Returns:
a negative integer if this instance is less than
another; a positive integer if this instance is greater thananother; 0 if this instance has the same order asanother.Throws
ClassCastException: @throws ClassCastException ifanothercannot be converted into something comparable tothisinstance.
-
name
The canonical name. -
displayName
The canonical name. -
displayName
-
aliases
-
isRegistered
public final boolean isRegistered()Whether the charset is registered with IANA: the three this runtime has are, and a name with the reservedX-prefix never is. -
canEncode
public boolean canEncode()Whether the charset can encode; the three this runtime has can. -
equals
-
hashCode
-
toString
-
defaultCharset
UTF-8, the default charset of this runtime on every platform. -
isSupported
Whether
charsetNamenames a charset this runtime has.Throws
IllegalCharsetNameException: if the name is not a legal charset nameIllegalArgumentException: if it is null
-
forName
The charset
charsetNamenames, by canonical name or alias, in any case.Throws
IllegalCharsetNameException: if the name is not a legal charset nameUnsupportedCharsetException: if this runtime has no such charsetIllegalArgumentException: if it is null
-
forName
-