Android ByteBuffer Create createByteBuffer(byte[] data)

Here you can find the source of createByteBuffer(byte[] data)

Description

Creates a ByteBuffer from the specified byte array.

Parameter

Parameter Description
data byte array to convert to a ByteBuffer

Return

ByteBuffer with the same content as data

Declaration

public static ByteBuffer createByteBuffer(byte[] data) 

Method Source Code

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

public class Main {
    /**//  w w w.  ja v a2 s.  c om
     * Creates a ByteBuffer with the specified capacity.
     * 
     * @param capacity
     *            buffer capacity
     * @return ByteBuffer with the specified capacity
     */
    public static ByteBuffer createByteBuffer(int capacity) {
        ByteBuffer b = ByteBuffer.allocateDirect(capacity);
        b.order(ByteOrder.nativeOrder());
        return b;
    }

    /**
     * Creates a ByteBuffer from the specified byte array.
     * 
     * @param data
     *            byte array to convert to a ByteBuffer
     * @return ByteBuffer with the same content as data
     */
    public static ByteBuffer createByteBuffer(byte[] data) {
        ByteBuffer b = createByteBuffer(data.length);
        b.put(data);
        b.rewind();
        return b;
    }
}

Related

  1. copy(float[] src, ByteBuffer dst, int numFloats, int offset)
  2. newByteBuffer(int numBytes)
  3. newByteBuffer(int numBytes)
  4. newUnsafeByteBuffer(ByteBuffer buffer)
  5. newUnsafeByteBuffer(int numBytes)
  6. createByteBuffer(int capacity)
  7. createByteBuffer(int count)
  8. createByteBuffer(int size)
  9. createByteBuffer(int size)