List of utility methods to do Charset Decode
boolean | canEncode(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); ... |