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

DoubledecodeDouble(ByteBuffer bb)
decode Double
return bb.getDouble();
intdecodeInt(ByteBuffer buffer, int start)
decode Int
return buffer.getInt(start);
StringdecodeIO(String encoding, ByteBuffer bbuf)
decode IO
if (bbuf.hasArray())
    return new String(bbuf.array(), encoding);
throw new IllegalArgumentException();
intdecodeLength(ByteBuffer buf)
Decode octets and extract the length information from a DER-encoded message.
if (buf == null || buf.remaining() == 0) {
    throw new IllegalArgumentException("Null or empty buffer");
int len = 0;
byte first = buf.get();
if (first >> 7 == 0) {
    len = first & 0x7f;
} else {
...
longdecodeLong(ByteBuffer buffer, int start)
decode Long
return buffer.getLong(start);
StringdecodeNIO(String encoding, ByteBuffer bbuf)
decode NIO
Charset cset = Charset.forName(encoding);
CharsetDecoder csetdecoder = cset.newDecoder();
csetdecoder.onMalformedInput(CodingErrorAction.REPLACE);
csetdecoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
try {
    CharBuffer cbuf = csetdecoder.decode(bbuf);
    return cbuf.toString();
} catch (CharacterCodingException e) {
...
longdecodeNumber(byte firstByte, ByteBuffer buffer)
decode Number
boolean isNeg = testBit(firstByte, OB_INT_SIGN_BIT_POS);
byte lenOrValue = (byte) (firstByte & OB_INT_VALUE_MASK);
if (lenOrValue <= OB_MAX_INT_1B) {
    return isNeg ? -lenOrValue : lenOrValue;
} else {
    long value = 0;
    long len = lenOrValue - OB_MAX_INT_1B;
    if (len == 5 || len == 7) {
...
intdecodeStoredBits(ByteBuffer bb)
decode Stored Bits
return bb.getInt();
ListdecodeStringSequence(ByteBuffer bb)
decode String Sequence
List<String> names = new ArrayList<String>();
bb.mark(); 
while (bb.hasRemaining()) {
    if (bb.get() == 0) {
        ByteBuffer nameBuffer = (ByteBuffer) bb.duplicate().limit(bb.position() - 1).reset();
        if (nameBuffer.hasRemaining()) {
            names.add(decodeString(nameBuffer));
        bb.mark(); 
return names;
CharBufferdecodeThrowing(Charset charset, ByteBuffer in)
Decodes in using charset , ensuring that a CharacterCodingException is thrown on invalid input.
return charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
        .onUnmappableCharacter(CodingErrorAction.REPORT).decode(in);