public class CheckedCharsetName extends java.lang.Object implements ICheckedCharset, java.io.Serializable
It helps to avoid the annoying try-catch code-pollution every time you use a valid encoding, but the API requires the handling of UnsupportedEncodingException even if it cannot occur at all.
Modifier and Type | Field and Description |
---|---|
static CheckedCharsetName |
DEFAULT
The platform default file encoding.
|
static CheckedCharsetName |
ISO_8859_1
The pre-defined constant for Java standard charset ISO-8859-1.
|
static CheckedCharsetName |
US_ASCII
The pre-defined constant for Java standard charset US-ASCII.
|
static CheckedCharsetName |
UTF_16
The pre-defined constant for Java standard charset UTF-16.
|
static CheckedCharsetName |
UTF_16BE
The pre-defined constant for Java standard charset UTF-16BE.
|
static CheckedCharsetName |
UTF_16LE
The pre-defined constant for Java standard charset UTF-16LE.
|
static CheckedCharsetName |
UTF_8
The pre-defined constant for Java standard charset UTF-8.
|
Constructor and Description |
---|
CheckedCharsetName(java.lang.String encodingName)
Initialize the new instance with an encoding name (e.g.
|
Modifier and Type | Method and Description |
---|---|
static void |
checkEncoding(java.lang.String charsetName)
Checks whether or not the given encoding is supported.
|
static CheckedCharsetName |
create(java.lang.String encodingName)
Creates a new instance based on the given encoding name.
|
boolean |
equals(java.lang.Object obj) |
byte[] |
getBytes(java.lang.String string)
Returns the bytes of the given string as array encoded to the charset
this instance represents, avoiding the unnecessary exception handling
(UnsupportedEncodingException).
|
java.nio.charset.Charset |
getCharset()
Returns the corresponding charset object.
|
java.lang.String |
getName()
Returns the pure upper case encoding name (e.g.
|
int |
hashCode() |
java.lang.String |
newString(byte[] bytes)
Returns a new String initialized with the given bytes which are expected
to be encoded according to the character set this instance represents,
avoiding the unnecessary exception handling (UnsupportedEncodingException).
|
java.lang.String |
toString()
Returns the pure upper case encoding name (e.g.
|
public static final CheckedCharsetName US_ASCII
public static final CheckedCharsetName ISO_8859_1
public static final CheckedCharsetName UTF_8
public static final CheckedCharsetName UTF_16
public static final CheckedCharsetName UTF_16BE
public static final CheckedCharsetName UTF_16LE
public static final CheckedCharsetName DEFAULT
public CheckedCharsetName(java.lang.String encodingName) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public static void checkEncoding(java.lang.String charsetName) throws java.io.UnsupportedEncodingException
charsetName
- The name of the encoding to check (e.g. "UTF-16")java.io.UnsupportedEncodingException
- Will be thrown if the encoding is not supported.public static CheckedCharsetName create(java.lang.String encodingName) throws java.io.UnsupportedEncodingException
encodingName
- The name of the encoding to check (e.g. "UTF-16")java.io.UnsupportedEncodingException
- Will be thrown if the encoding is not supported.public java.lang.String getName()
getName
in interface ICheckedCharset
public java.nio.charset.Charset getCharset()
getCharset
in interface ICheckedCharset
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String newString(byte[] bytes)
It is the same like: new String(bytes, checkedCharsetName.toString());
newString
in interface ICheckedCharset
bytes
- The byte to create a string from.public byte[] getBytes(java.lang.String string)
getBytes
in interface ICheckedCharset
string
- The string to be converted to a byte array using this instance's charset.