Java Utililty Methods ByteBuffer to String

List of utility methods to do ByteBuffer to String

Description

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

Method

StringgetString(ByteBuffer in, int maxLength)
Read a string from the buffer.
int l = in.getInt();
if (maxLength > 0 && l > maxLength)
    throw new BufferOverflowException();
byte[] b = new byte[l];
try {
    in.get(b);
    return new String(b, "ISO-8859-1");
} catch (BufferUnderflowException bue) {
...
StringgetString(final ByteBuffer buffer)
Reads a String from a ByteBuffer.
int length = buffer.getInt();
char[] chBuffer = new char[length];
for (int i = 0; i < length; i++) {
    chBuffer[i] = buffer.getChar();
return new String(chBuffer);
StringgetString(final ByteBuffer buffer, final int offset, final int length, final Charset encoding)
Reads bytes from a ByteBuffer as if they were encoded in the specified CharSet.
final byte[] b = new byte[length];
buffer.position(buffer.position() + offset);
buffer.get(b);
return new String(b, 0, length, encoding);
StringgetString(java.nio.ByteBuffer buffer, int offset, int len)
get String
String s = "";
if (null != buffer && buffer.capacity() >= offset + len) {
    byte[] dest = new byte[len];
    buffer.position(offset);
    buffer.get(dest, 0, len);
    s = new String(dest).trim();
return s;
...
StringgetStringA(ByteBuffer byteBuffer, int length)
get String A
byte[] dst = getBytes(byteBuffer, length);
return new String(dst);
StringgetStringDTrimmed(ByteBuffer byteBuffer, int length)
get String D Trimmed
return getStringD(byteBuffer, length).trim();
StringgetStringFromBuffer(ByteBuffer buf, int len)
get String From Buffer
byte[] bytes = new byte[len];
buf.get(bytes);
return esc0(new String(bytes));
StringgetStringFromBuffer(ByteBuffer buffer, int length)
get String From Buffer
char[] arr = new char[length];
for (int i = 0; i < length; i++) {
    arr[i] = buffer.getChar();
return new String(arr);
StringgetStringFromByteBuffer(ByteBuffer bb)
Returns a String representation of a ByteBuffer.
StringBuilder message = new StringBuilder();
int bytes;
while (true) {
    try {
        bytes = bb.get();
        message.append("\\x" + String.format("%02x", bytes & 0xff));
    } catch (Exception e) {
        break;
...
StringgetStringFromByteBuffer(ByteBuffer data)
string from ByteBuffer
return new String(data.array(), ENCODING);