Java Utililty Methods ByteBuffer Decode

List of utility methods to do ByteBuffer Decode

Description

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

Method

longdecodeTime(byte firstByte, ByteBuffer buffer)
decode Time
boolean isNeg = testBit(firstByte, OB_DATETIME_SIGN_BIT);
long value = decodeTimeWithoutSign(firstByte, buffer);
return isNeg ? -value : value;
longdecodeTimeWithoutSign(byte firstByte, ByteBuffer buffer)
decode Time Without Sign
int lenMark = firstByte & OB_DATETIME_LEN_MASK;
int len = 0;
if (lenMark == 0) {
    len = 4;
} else if (lenMark == 1) {
    len = 6;
} else if (lenMark == 2) {
    len = 8;
...
StringdecodeToString(ByteBuffer shaderInfoLogBuffer, IntBuffer size)
Decode the ByteBuffer into an UTF-8 String.
int s = size.get(0);
byte[] bs = new byte[s];
shaderInfoLogBuffer.get(bs, 0, bs.length);
return new String(bs, CHARSET_UTF8);
StringdecodeUtf8(ByteBuffer bytes)
decode Utf
if (bytes == null)
    return null;
return new String(CharsetUTF8.newDecoder().decode(bytes).array());
StringdecodeUTF8(ByteBuffer utf8Data)
Convenience method for decoding a UTF-8 ByteBuffer into a Java String .
try {
    return utf8Charset.newDecoder().decode(utf8Data).toString();
} catch (CharacterCodingException ex) {
    ex.printStackTrace();
    return null;
StringdecodeUTF8(final ByteBuffer buf)
Decode the content of the given ByteBuffer, from its position to its limit, to a String.
return Charset.forName("UTF-8").decode(buf).toString();
voidfillBuf(InputStream in, ByteBuffer bytes, CharBuffer chars, CharsetDecoder decoder)
fill Buf
chars.clear();
int read = 0;
try {
    read = in.read(bytes.array());
} catch (IOException e) {
    chars.limit(0);
    throw e;
if (read == -1) {
    chars.limit(0);
    return;
bytes.limit(read);
boolean endOfInput = read < DEFAULT_BUFFER_SIZE;
CoderResult result = decoder.decode(bytes, chars, endOfInput);
if (result.isError()) {
    throw new IOException(result.toString());
bytes.clear();
chars.flip();
intreadInputStreamReader(InputStream in, ByteBuffer bytes, CharBuffer chars, CharsetDecoder decoder, Object lock)
read Input Stream Reader
synchronized (lock) {
    if (in != null) {
        if (chars.limit() == chars.position()) {
            fillBuf(in, bytes, chars, decoder);
        if (chars.limit() == 0) {
            return -1;
        return chars.get();
    throw new IOException("InputStreamReader is closed");