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

CharBufferbytesToChars(CharsetDecoder decoder, ByteBuffer bytes, CharBuffer chars)
Convert byte buffer's content into characters.
assert decoder.malformedInputAction() == CodingErrorAction.REPORT;
chars = clearAndEnsureCapacity(chars, (int) (bytes.remaining() * decoder.maxCharsPerByte()));
bytes.mark();
decoder.reset();
CoderResult cr = decoder.decode(bytes, chars, true);
if (cr.isError()) {
    bytes.reset();
    try {
...
Stringdecode(byte firstByte, ByteBuffer buffer, String charset)
decode
int lenOrValue = firstByte & OB_VARCHAR_LEN_MASK;
int strLen = 0;
if (lenOrValue <= OB_MAX_1B_STR_LEN) {
    strLen = lenOrValue;
} else {
    for (int n = 0; n < lenOrValue - OB_MAX_1B_STR_LEN; n++) {
        strLen |= ((buffer.get() & 0xffl) << (n << 3));
byte[] ret = new byte[strLen];
buffer.get(ret);
try {
    return new String(ret, charset);
} catch (UnsupportedEncodingException e) {
    return "";
Stringdecode(ByteBuffer bb)
decode
return charset.decode(bb).toString();
Stringdecode(ByteBuffer bb, CharsetDecoder decoder)
decode
CharBuffer cb = CharBuffer.allocate(128);
CoderResult result = decoder.decode((ByteBuffer) bb.flip(), cb, true );
if (result.isError()) {
    throw new IllegalArgumentException("Malformed UTF-8!");
return ((CharBuffer) cb.flip()).toString();
Stringdecode(Charset charset, ByteBuffer buffer)
decode
CharBuffer cb = charset.decode(buffer);
return cb.toString();
voiddecode(CharsetDecoder decoder, ByteBuffer src, CharBuffer dst)
decode
try {
    CoderResult cr = decoder.decode(src, dst, true);
    if (!cr.isUnderflow()) {
        cr.throwException();
    cr = decoder.flush(dst);
    if (!cr.isUnderflow()) {
        cr.throwException();
...
CharBufferdecode(String charsetName, ByteBuffer byteBuffer)
decode
try {
    CharsetDecoder charsetDecoder = getCharsetDecoder(charsetName);
    return charsetDecoder.decode(byteBuffer);
} catch (CharacterCodingException cce) {
    throw new Error(cce);
voiddecodeAlign(ByteBuffer buf)
decode Align
final int pos = buf.position();
final int newPos = aligned(pos);
if (buf.limit() < newPos)
    throw new BufferUnderflowException();
buf.position(newPos);
StringdecodeASCII(ByteBuffer buffer, int length, int offset)
decode ASCII
char[] chars = new char[length];
for (int i = 0; i < length; i++)
    chars[i] = (char) buffer.get(offset + i);
return new String(chars);
StringdecodeBuffer(ByteBuffer buffer, String charsetName)
decode Buffer
byte[] bytes = new byte[buffer.limit()];
buffer.get(bytes);
try {
    return new String(bytes, charsetName);
} catch (UnsupportedEncodingException e) {
    return new String(bytes);