Java ByteBuffer to Long readLong64ls(int size, ByteBuffer byteBuf)

Here you can find the source of readLong64ls(int size, ByteBuffer byteBuf)

Description

read Longls

License

Apache License

Declaration

static long readLong64ls(int size, ByteBuffer byteBuf) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.nio.ByteBuffer;

public class Main {
    static long readLong64ls(int size, ByteBuffer byteBuf) throws Exception {
        switch (size) {
        case 0://w w  w.  ja v  a  2  s . c om
            return 0;
        case 1:
            return byteBuf.get();
        case 2:
            return byteBuf.getShort();
        case 3:
            return (byteBuf.get() << 16) + readUnsignedShort(byteBuf);
        case 4:
            return byteBuf.getInt();
        case 5:
            return (((long) (byteBuf.get())) << 32)
                    + readUnsignedInt(byteBuf);
        case 6:
            return (((long) (byteBuf.getShort())) << 32)
                    + readUnsignedInt(byteBuf);
        case 7:
            return (((long) (byteBuf.get())) << 48)
                    + (((long) (readUnsignedShort(byteBuf))) << 32)
                    + readUnsignedInt(byteBuf);
        case 8:
            return byteBuf.getLong();
        default:
            assert (false);
            return 0;
        }
    }

    static int readUnsignedShort(ByteBuffer byteBuf) throws Exception {
        int val = byteBuf.getShort();

        if (val < 0)
            val &= 0xFFFF;

        return val;
    }

    static long readUnsignedInt(ByteBuffer byteBuf) throws Exception {
        long val = byteBuf.getInt();
        if (val < 0)
            val &= 0xFFFFFFFFL;
        return val;
    }
}

Related

  1. readLong(ByteBuffer buffer)
  2. readLong(ByteBuffer buffer)
  3. readLong(ByteBuffer in)
  4. readLong(ByteBuffer in, final int fitInBytes)
  5. readLong(ByteBuffer logBuf)
  6. readLongArray(ByteBuffer bb)
  7. readLongLE(ByteBuffer buf, int i)
  8. readUB1(ByteBuffer buffer)
  9. readUB4(ByteBuffer buffer)