Java Utililty Methods String Decode by Charset

List of utility methods to do String Decode by Charset

Description

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

Method

CharsetDecodergetCharsetDecoder(String charsetName)
get Charset Decoder
Charset charset = Charset.forName(charsetName);
CharsetDecoder charsetDecoder = charset.newDecoder();
charsetDecoder.onMalformedInput(CodingErrorAction.REPLACE);
charsetDecoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
return charsetDecoder;
CharsetDecodergetDecoder(Charset charset)
Returns a cached thread-local CharsetDecoder for the specified charset.
if (charset == null) {
    throw new NullPointerException("charset");
Map<Charset, CharsetDecoder> map = decoders.get();
CharsetDecoder d = map.get(charset);
if (d != null) {
    d.reset();
    d.onMalformedInput(CodingErrorAction.REPLACE);
...
CharsetDecodergetDecoder(Charset charset)
get Decoder
if (charset == null)
    throw new IllegalArgumentException(
            "charset cannot be null, consider using one of the pre-defined Charset constants from this class for convenience.");
CharsetDecoder result = decoderMap.get(charset);
if (result == null) {
    result = charset.newDecoder();
    decoderMap.put(charset, result);
return result;
CharsetDecodergetDecoder(String charset)
get Decoder
return Charset.forName(charset).newDecoder();
CharBufferpooledCharBuffer(int len, CharsetDecoder decoder)
pooled Char Buffer
final int maxLength = (int) ((double) len * decoder.maxCharsPerByte());
CharBuffer dst = CHAR_BUFFERS.get();
if (dst.length() < maxLength) {
    dst = CharBuffer.allocate(maxLength);
    CHAR_BUFFERS.set(dst);
} else {
    dst.clear();
return dst;
CharsetDecoderreportingDecoder(Charset cset)
reporting Decoder
return cset.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
        .onUnmappableCharacter(CodingErrorAction.REPORT);
StringstringDecoder(String string, Charset charset)
Decodes the bytes in a String of a given Charset, into Unicode (i.e.
Charset characterSet = charset;
if (characterSet == null) {
    characterSet = Charset.forName(UTF8);
CharBuffer cb = characterSet.decode(ByteBuffer.wrap(string.getBytes()));
return new String(cb.array());
StringunicodeCodePoint2PercentHexString(int codePoint, String charsetName)
Return the percentHexOctets string that represents the given Unicode code point in the given character set or null if the given character set cannot encode the given code point.
if (!Character.isDefined(codePoint))
    throw new IllegalArgumentException("Not a valid Unicode code point [" + codePoint + "].");
Charset charset = Charset.availableCharsets().get(charsetName);
if (charset == null)
    throw new IllegalArgumentException("Unsupported charset [" + charsetName + "].");
char[] chars = Character.toChars(codePoint);
ByteBuffer byteBuffer = null;
try {
...
StringurlDecode(final String str, final Charset encoding)
url Decode
try {
    return URLDecoder.decode(str, encoding.name());
} catch (final UnsupportedEncodingException x) {
    throw new RuntimeException(x);