Android ByteBuffer Create arr2ByteBuffer(float[] arr)

Here you can find the source of arr2ByteBuffer(float[] arr)

Description

arr Byte Buffer

Declaration

public static ByteBuffer arr2ByteBuffer(float[] arr) 

Method Source Code

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

public class Main {

    public static ByteBuffer arr2ByteBuffer(float[] arr) {

        ByteBuffer ibb = ByteBuffer.allocateDirect(arr.length * 4);
        ibb.order(ByteOrder.nativeOrder());
        FloatBuffer fbb = ibb.asFloatBuffer();
        fbb.put(arr);//  ww w.  jav  a2 s  .c  o  m
        ibb.position(0);
        return ibb;
    }

    public static ByteBuffer arr2ByteBuffer(byte[] arr) {

        ByteBuffer ibb = ByteBuffer.allocateDirect(arr.length);
        ibb.order(ByteOrder.nativeOrder());
        ibb.put(arr);
        ibb.position(0);
        return ibb;
    }
}

Related

  1. createDirectByteBuffer( final int capacity, final ByteBuffer previous)
  2. createDirectByteBuffer(final int capacity)
  3. arr2ByteBuffer(byte [] arr)
  4. arr2ByteBuffer(byte[] arr)
  5. arr2ByteBuffer(float [] arr)
  6. list2ByteBuffer(List arr)
  7. list2ByteBuffer(List list)
  8. makeByteBuffer(byte[] arr)
  9. makeByteBuffer(int size)