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

StringgetStringRepresentation(ByteBuffer key)
get String Representation
Charset charset = Charset.forName("ISO-8859-1");
CharsetDecoder decoder = charset.newDecoder();
String keyName = null;
ByteBuffer keyNameByteBuffer = key.duplicate();
CharBuffer keyNameCharBuffer;
try {
    keyNameCharBuffer = decoder.decode(keyNameByteBuffer);
    keyName = keyNameCharBuffer.toString();
...
StringgetStringTrimmed(ByteBuffer buffer, int size)
Strings in the file are zero-terminated.
return getString(buffer, size).trim();
StringgetStringWOLength(ByteBuffer bb)
get String WO Length
byte[] b = new byte[bb.limit()];
bb.get(b);
return new String(b, Charset.forName("UTF-8"));
StringreadStr(ByteBuffer bb, int off, int len)
read Str
return readStr(bb, off, len, OLE_CHARSET);
StringreadString(byte[] tmp, ByteBuffer in)
read String
int len = in.get() & 0xff;
in.get(tmp, 0, len);
return new String(tmp, 0, len, StandardCharsets.UTF_8);
voidreadString(ByteBuffer b, char s[], int off, int len)
read String
while (off < len) {
    s[off++] = b.getChar();
StringreadString(ByteBuffer bb)
read String
int len = (int) bb.getShort();
byte[] stringBytes = new byte[len];
bb.get(stringBytes);
return new String(stringBytes);
StringreadString(ByteBuffer bb)
read String
int length = bb.get();
byte strBytes[] = new byte[length];
bb.get(strBytes);
try {
    return new String(strBytes, STORED_ENCODING);
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException(e);
StringreadString(ByteBuffer bb, int limit)
Reads a null-terminated string from the current position of the given bytebuffer.
int max = Math.min(limit, bb.remaining());
byte[] name = new byte[max];
bb.get(name);
return readString(name, max);
StringreadString(ByteBuffer buf)
read String
StringBuilder bldr = new StringBuilder();
char c = (char) buf.get();
while (c != '\0') {
    bldr.append(c);
    c = (char) buf.get();
return bldr.toString();