Java Utililty Methods ByteBuffer to UTF

List of utility methods to do ByteBuffer to UTF

Description

The list of methods to do ByteBuffer to UTF are organized into topic(s).

Method

StringreadUTF(ByteBuffer bb)
Reads from the bytebuffer bb a representation of a Unicode character string encoded in modified UTF-8 format; this string of characters is then returned as a String.
int utflen = readUnsignedShort(bb);
byte[] bytearr = new byte[utflen];
char[] chararr = new char[utflen];
int c, char2, char3;
int count = 0;
int chararr_count = 0;
bb.get(bytearr);
while (count < utflen) {
...
StringreadUTF8(ByteBuffer buf)
read UTF
short len = buf.getShort();
byte[] str = new byte[len];
buf.get(str);
String res = null;
try {
    res = new String(str, "UTF-8");
} catch (UnsupportedEncodingException ex) {
    res = "";
...
StringreadUTFString(MappedByteBuffer mmap)
read UTF String
byte[] encodedString = new byte[mmap.getShort()];
mmap.get(encodedString);
return new String(encodedString, Charset.forName("UTF-8"));
CharBuffertoUtf8CharBuffer(ByteBuffer buffer)
Converts the input ByteBuffer in an UTF-8 CharBuffer .
return UTF_8.decode(buffer);
StringtoUtf8String(ByteBuffer buffer)
to Utf String
if (!buffer.hasRemaining()) {
    return EMPTY;
if (buffer.hasArray()) {
    return new String(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining(),
            StandardCharsets.UTF_8);
} else {
    byte[] content = new byte[buffer.remaining()];
...
StringtoUTF8String(ByteBuffer buffer)
Convert the buffer to an UTF-8 String
return toString(buffer, StandardCharsets.UTF_8);
StringtoUtf8String(ByteBuffer byteBuffer)
to Utf String
byte[] bytes = new byte[byteBuffer.remaining()];
byteBuffer.get(bytes);
return new String(bytes, UTF_8);