Example usage for java.nio ByteBuffer asShortBuffer

List of usage examples for java.nio ByteBuffer asShortBuffer

Introduction

In this page you can find the example usage for java.nio ByteBuffer asShortBuffer.

Prototype

public abstract ShortBuffer asShortBuffer();

Source Link

Document

Returns a short buffer which is based on the remaining content of this byte buffer.

Usage

From source file:Main.java

public static ShortBuffer allocateShortBuffer(int capacity) {
    final ByteBuffer vbb = ByteBuffer.allocateDirect(capacity);
    vbb.order(ByteOrder.nativeOrder());
    return vbb.asShortBuffer();
}

From source file:Main.java

public static ShortBuffer newShortBuffer(int numShorts) {
    ByteBuffer buffer = ByteBuffer.allocateDirect(numShorts * 2);
    buffer.order(ByteOrder.nativeOrder());
    return buffer.asShortBuffer();
}

From source file:Main.java

public static ShortBuffer toShortBuffer(short[] v) {
    ByteBuffer buff = ByteBuffer.allocateDirect(v.length * 2);
    buff.order(ByteOrder.nativeOrder());
    ShortBuffer buffer = buff.asShortBuffer();
    buffer.put(v);//from www.  j  a v  a  2s .  c  om
    buffer.position(0);
    return buffer;
}

From source file:Main.java

/**
 * //from  ww w. ja va2 s . c o m
 * @since 1.0.0
 * @param v
 * @return the ShortBuffer
 */
public static ShortBuffer toShortBuffer(short[] v) {
    ByteBuffer buf = ByteBuffer.allocateDirect(v.length * 2);
    buf.order(ByteOrder.nativeOrder());
    ShortBuffer buffer = buf.asShortBuffer();
    buffer.put(v);
    buffer.position(0);
    return buffer;
}

From source file:Main.java

public static ShortBuffer getShortBuffer(short[] coords) {
    ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * 2);
    bb.order(ByteOrder.nativeOrder());
    ShortBuffer shortBuffer = bb.asShortBuffer();
    shortBuffer.put(coords);//ww  w. j  ava2 s. co  m
    shortBuffer.position(0);
    return shortBuffer;
}

From source file:Main.java

public static ShortBuffer buildShortBuffer(short[] array) {
    ByteBuffer byteBuf = ByteBuffer.allocateDirect(array.length * 2);
    byteBuf.order(ByteOrder.nativeOrder());
    ShortBuffer buffer = byteBuf.asShortBuffer();
    buffer.put(array);//from ww  w.  ja v a 2  s . c  om
    buffer.position(0);
    return buffer;
}

From source file:Main.java

public static ShortBuffer toShortBuffer(short[] values) {
    ByteBuffer vbb = ByteBuffer.allocateDirect(values.length * 2);
    vbb.order(ByteOrder.nativeOrder());
    ShortBuffer buffer = vbb.asShortBuffer();
    buffer.put(values);/*from ww w  .j  a v  a  2  s  .  c  o  m*/
    buffer.position(0);
    return buffer;
}

From source file:Main.java

public static ShortBuffer transportArrayToNativeBuffer(short[] sArray) {
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(sArray.length * 2);
    byteBuffer.order(ByteOrder.nativeOrder());
    return (ShortBuffer) byteBuffer.asShortBuffer().put(sArray).position(0);
}

From source file:Main.java

public static ShortBuffer makeShortBuffer(short[] array) {
    if (array == null)
        throw new IllegalArgumentException();

    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(2 * array.length);
    byteBuffer.order(ByteOrder.nativeOrder());
    ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
    shortBuffer.put(array);/*  w  ww.  ja v  a 2  s. co m*/
    shortBuffer.position(0);
    return shortBuffer;
}

From source file:Main.java

public static ShortBuffer toShortBuffer(short[] values) {
    final ByteBuffer vbb = ByteBuffer.allocateDirect(values.length * 2);
    vbb.order(ByteOrder.nativeOrder());
    final ShortBuffer buffer = vbb.asShortBuffer();
    buffer.put(values);/*  ww  w.  jav  a2s.co  m*/
    buffer.position(0);
    return buffer;
}