Java ByteBuffer Endian convertLittleEndianLong(ByteBuffer buff, int size)

Here you can find the source of convertLittleEndianLong(ByteBuffer buff, int size)

Description

convert Little Endian Long

License

Apache License

Declaration

public static long convertLittleEndianLong(ByteBuffer buff, int size) 

Method Source Code

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

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class Main {
    private static final int LONG_SIZE = 8;

    public static long convertLittleEndianLong(ByteBuffer buff, int size) {
        if (size <= 0 || size > LONG_SIZE) {
            throw new IllegalArgumentException("size MUST be less 8.");
        }/*from ww w .j av a  2s. c  o m*/
        byte[] array = new byte[size];
        buff.get(array);
        ByteBuffer bbf = ByteBuffer.allocate(LONG_SIZE);
        bbf.put(array);
        bbf.order(ByteOrder.LITTLE_ENDIAN);
        if (size < LONG_SIZE) {
            bbf.position(LONG_SIZE);
        }
        bbf.flip();
        return bbf.getLong();
    }
}

Related

  1. assertByteOrderLittleEndian(ByteBuffer buffer)
  2. decodeLittleEndianFixedWidthLong(ByteBuffer buffer)
  3. decodeLittleEndianVarInt(ByteBuffer buffer)
  4. extractInt(ByteBuffer header_buf, boolean bigEndian)
  5. extractShort(ByteBuffer buffer, boolean bigEndian)