Android ByteBuffer Create makeByteBuffer(byte[] arr, int length)

Here you can find the source of makeByteBuffer(byte[] arr, int length)

Description

make Byte Buffer

Declaration

public static ByteBuffer makeByteBuffer(byte[] arr, int length) 

Method Source Code

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

public class Main {
    /**//  w  ww.  jav a  2 s.c o m
     * Make a direct NIO ByteBuffer from an array of floats
     * @param arr The array
     * @return The newly created FloatBuffer
     */
    public static ByteBuffer makeByteBuffer(byte[] arr) {
        ByteBuffer bb = ByteBuffer.allocateDirect(arr.length);
        bb.order(ByteOrder.nativeOrder());
        bb.put(arr);
        bb.position(0);
        return bb;
    }

    public static ByteBuffer makeByteBuffer(byte[] arr, int length) {
        ByteBuffer bb = ByteBuffer.allocateDirect(length);
        bb.order(ByteOrder.nativeOrder());
        bb.put(arr, 0, length);
        bb.position(0);

        return bb;
    }

    public static ByteBuffer makeByteBuffer(int size) {
        ByteBuffer bb = ByteBuffer.allocateDirect(size);
        bb.position(0);
        return bb;
    }
}

Related

  1. ConvToByteBuffer(byte buf[])
  2. ConvToByteBuffer(byte buf[])
  3. makeByteBuffer(byte[] arr)
  4. makeByteBuffer(byte[] arr)
  5. makeByteBuffer(byte[] arr)
  6. makeByteBuffer(byte[] i_arr)
  7. makeByteBuffer(int size)
  8. makeByteBuffer(int size)
  9. makeByteBuffer(int size)