Java ByteBuffer Decode decodeTime(byte firstByte, ByteBuffer buffer)

Here you can find the source of decodeTime(byte firstByte, ByteBuffer buffer)

Description

decode Time

License

Open Source License

Declaration

public static long decodeTime(byte firstByte, ByteBuffer buffer) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    private static final byte OB_DATETIME_SIGN_BIT = 2;
    private static final byte OB_DATETIME_LEN_MASK = 0x03;

    public static long decodeTime(byte firstByte, ByteBuffer buffer) {
        boolean isNeg = testBit(firstByte, OB_DATETIME_SIGN_BIT);
        long value = decodeTimeWithoutSign(firstByte, buffer);
        return isNeg ? -value : value;
    }//from   w  w  w.j av  a  2s. c o  m

    private static boolean testBit(byte target, byte pos) {
        return 0 != (target & (1 << pos));
    }

    public static long decodeTimeWithoutSign(byte firstByte,
            ByteBuffer buffer) {
        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;
        }
        long value = 0;
        for (int n = 0; n < len; n++) {
            value |= ((buffer.get() & 0xffl) << (n << 3));
        }
        return value;
    }
}

Related

  1. decodeNIO(String encoding, ByteBuffer bbuf)
  2. decodeNumber(byte firstByte, ByteBuffer buffer)
  3. decodeStoredBits(ByteBuffer bb)
  4. decodeStringSequence(ByteBuffer bb)
  5. decodeThrowing(Charset charset, ByteBuffer in)
  6. decodeTimeWithoutSign(byte firstByte, ByteBuffer buffer)
  7. decodeToString(ByteBuffer shaderInfoLogBuffer, IntBuffer size)
  8. decodeUtf8(ByteBuffer bytes)
  9. decodeUTF8(ByteBuffer utf8Data)