Android ShortBuffer Create createShortBuffer(int capacity)

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

Description

Creates a ShortBuffer with the specified capacity.

Parameter

Parameter Description
capacity buffer capacity

Return

ShortBuffer with the specified capacity

Declaration

public static ShortBuffer createShortBuffer(int capacity) 

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 va2s . com*/
     * 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. copy(short[] src, ShortBuffer dst, int numShorts, int offset)
  2. newShortBuffer(int numShorts)
  3. newShortBuffer(int numShorts)
  4. createShortBuffer(int shortCount)
  5. createShortBuffer(int size)
  6. createShortBuffer(int size)
  7. createShortBuffer(short[] data)