Android ByteBuffer Create createByteBuffer(int capacity)

Here you can find the source of createByteBuffer(int capacity)

Description

Creates a ByteBuffer with the specified capacity.

Parameter

Parameter Description
capacity buffer capacity

Return

ByteBuffer with the specified capacity

Declaration

public static ByteBuffer createByteBuffer(int capacity) 

Method Source Code

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

public class Main {
    /**//from  w  w  w. j  a  v a  2s. c o m
     * 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. newByteBuffer(int numBytes)
  2. newByteBuffer(int numBytes)
  3. newUnsafeByteBuffer(ByteBuffer buffer)
  4. newUnsafeByteBuffer(int numBytes)
  5. createByteBuffer(byte[] data)
  6. createByteBuffer(int count)
  7. createByteBuffer(int size)
  8. createByteBuffer(int size)
  9. createDirectByteBuffer( final int capacity, final ByteBuffer previous)