Android Utililty Methods Charset Decode

List of utility methods to do Charset Decode

Description

The list of methods to do Charset Decode are organized into topic(s).

Method

booleancanEncode(char c)
Determines whether or not this platform's Charset#defaultCharset default Charset ) can encode c and then decode it back to the exact same value.
try {
    char[] charArray = new char[] { c };
    ByteBuffer byteBuffer = Charset.defaultCharset().newEncoder()
            .encode(java.nio.CharBuffer.wrap(charArray));
    char[] charArrayRestored = Charset.defaultCharset()
            .decode(byteBuffer).array();
    return (charArray[0] == charArrayRestored[0]);
} catch (CharacterCodingException cce) {
...
byte[]getBytes(String input, Charset charset)
Returns a new byte array containing the characters of the specified string encoded using the given charset.
CharBuffer chars = CharBuffer.wrap(input.toCharArray());
CharsetEncoder encoder = charset.newEncoder()
        .onMalformedInput(CodingErrorAction.REPLACE)
        .onUnmappableCharacter(CodingErrorAction.REPLACE);
ByteBuffer buffer;
buffer = encode(chars.asReadOnlyBuffer(), encoder);
byte[] bytes = new byte[buffer.limit()];
buffer.get(bytes);
...