org.pfsw.bif.text
Interface ICheckedCharset


public interface ICheckedCharset

Specifies the interface of objects that represents a character encoding name that has already been checked if it is supported by the platform.

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.


Method Summary
 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.
 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).
 

Method Detail

getName

java.lang.String getName()
Returns the pure upper case encoding name (e.g. "UTF-8").


getCharset

java.nio.charset.Charset getCharset()
Returns the corresponding charset object.


newString

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).

It is the same like: new String(bytes, checkedCharsetName.toString());

Parameters:
bytes - The byte to create a string from.
Returns:
A new string built from the given bytes that were encoded with the charset of this instance.

getBytes

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).

Parameters:
string - The string to be converted to a byte array using this instance's charset.
Returns:
The encoded byte array.