Android ShortBuffer Create createShortBuffer(short[] data)

Here you can find the source of createShortBuffer(short[] data)

Description

Creates a ShortBuffer from the specified short array.

Parameter

Parameter Description
data short array to convert to a ShortBuffer

Return

ShortBuffer with the same content as data

Declaration

public static ShortBuffer createShortBuffer(short[] data) 

Method Source Code

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

import java.nio.ShortBuffer;

public class Main {
    /**//  w  w  w  .  j a va 2s .c o m
     * Creates a ShortBuffer with the specified capacity.
     * 
     * @param capacity
     *            buffer capacity
     * @return ShortBuffer with the specified capacity
     */
    public static ShortBuffer createShortBuffer(int capacity) {
        return createByteBuffer(capacity * 2).asShortBuffer();
    }

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

    /**
     * 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. newShortBuffer(int numShorts)
  2. createShortBuffer(int capacity)
  3. createShortBuffer(int shortCount)
  4. createShortBuffer(int size)
  5. createShortBuffer(int size)
  6. createShortBuffer(short[] shortData)
  7. createShortIndicesBuffer( final int capacity)
  8. createShortIndicesBuffer( final int capacity, final ShortBuffer previous)
  9. newShortBuffer(int numShorts)