Java Utililty Methods Byte Array to String by Charset

List of utility methods to do Byte Array to String by Charset

Description

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

Method

booleanidentify(byte[] bytes, CharsetDecoder decoder)
identify
try {
    decoder.decode(ByteBuffer.wrap(bytes));
} catch (CharacterCodingException e) {
    return false;
return true;
Stringinflate(byte[] bytes, Charset encoding)
inflate
Inflater inf = new Inflater(true);
inf.reset();
inf.setInput(bytes);
byte[] buffer = getThreadBuffer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while (!inf.finished()) {
    int n = inf.inflate(buffer);
    baos.write(buffer, 0, n);
...
booleanisCharset(byte[] b, String inCharset)
is Charset
CharsetDecoder cd = Charset.availableCharsets().get(inCharset).newDecoder();
try {
    cd.decode(ByteBuffer.wrap(b));
} catch (CharacterCodingException e) {
    return false;
return true;
StringnewString(byte[] bytes, Charset charset)
new String
return bytes == null ? null : new String(bytes, charset);
StringnewString(byte[] bytes, String charsetName)
Constructs a new String by decoding the specified array of bytes using the given charset.
if (bytes == null) {
    return null;
try {
    return new String(bytes, charsetName);
} catch (Exception e) {
return null;
...
StringnewString(final byte[] bytes, final Charset charset)
new String
return bytes == null ? null : new String(bytes, charset);
StringnewString(final byte[] bytes, final Charset charset)
Constructs a new String by decoding the specified array of bytes using the given charset.
return bytes == null ? null : new String(bytes, charset);
StringnewStringFromSplit(CharsetDecoder decoder, CharsetDecoder utf8Decoder, String encoding, byte[] fieldBytes, int length)
new String From Split
ByteBuffer fieldBuf = ByteBuffer.wrap(fieldBytes, 0, length);
CharBuffer fieldCharBuf = CharBuffer.allocate(length);
utf8Decoder.reset();
CoderResult res = utf8Decoder.decode(fieldBuf, fieldCharBuf, true);
if (res.isError() && decoder != null) {
    decoder.reset();
    res = decoder.decode(fieldBuf, fieldCharBuf, true);
    if (!res.isError()) {
...
StringparseBytes(byte[] encoded, Charset charset)
parse Bytes
String decoded = new String(encoded, charset.name());
return decoded;
Stringstr(byte[] bytes, String charset)
str
return new String(bytes, Charset.forName(charset));