allocate Byte Buffer - Java java.nio

Java examples for java.nio:ByteBuffer

Description

allocate Byte Buffer

Demo Code


//package com.java2s;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class Main {
    public static void main(String[] argv) throws Exception {
        int numBytes = 2;
        System.out.println(allocateByteBuffer(numBytes));
    }//from  w ww  .  j a v a  2 s. com

    public static ByteBuffer allocateByteBuffer(int numBytes) {
        ByteBuffer bb;
        int allocationSize = numBytes;
        bb = ByteBuffer.allocateDirect(allocationSize);
        bb.order(ByteOrder.LITTLE_ENDIAN);
        return bb;
    }
}

Related Tutorials