Example usage for java.nio ShortBuffer put

List of usage examples for java.nio ShortBuffer put

Introduction

In this page you can find the example usage for java.nio ShortBuffer put.

Prototype

public ShortBuffer put(ShortBuffer src) 

Source Link

Document

Writes all the remaining shorts of the src short buffer to this buffer's current position, and increases both buffers' position by the number of shorts copied.

Usage

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);
    buffer.position(0);/*from  w  w w.  j a  v  a2  s .c o  m*/
    return buffer;
}

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);
    buffer.position(0);//  w  ww . j  av  a2 s .co m
    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);
    shortBuffer.position(0);//  w  w w. j av a2s.co  m
    return shortBuffer;
}

From source file:Main.java

/**
 * //  w w  w .  j  a v a  2s .  c om
 * @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 toShortBuffer(short[] values) {
    ByteBuffer vbb = ByteBuffer.allocateDirect(values.length * 2);
    vbb.order(ByteOrder.nativeOrder());
    ShortBuffer buffer = vbb.asShortBuffer();
    buffer.put(values);
    buffer.position(0);//from  w  w  w  .  java 2 s. c  o  m
    return buffer;
}

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);
    shortBuffer.position(0);//www.ja va  2  s .co m
    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);
    buffer.position(0);/*from   w w  w  . j  a v a 2  s  .c  o  m*/
    return buffer;
}

From source file:Main.java

public static void addIndex(ShortBuffer buffer, int index1, int index2, int index3) {
    buffer.put((short) index1);
    buffer.put((short) index2);
    buffer.put((short) index3);
}

From source file:Main.java

/**
 * Creates a {@link ShortBuffer} based on the given data.
 *
 * @param data the data for the buffer/*from w  w  w  .ja  v  a  2 s. co  m*/
 * @return the short buffer
 */
public static ShortBuffer createShortBuffer(final short[] data) {
    if (data == null) {
        return null;
    }
    ByteBuffer bbVertices = ByteBuffer.allocateDirect(data.length * 4);
    bbVertices.order(ByteOrder.nativeOrder());
    final ShortBuffer fBuffer = bbVertices.asShortBuffer();
    fBuffer.put(data);
    fBuffer.position(0);
    return fBuffer;
}

From source file:Main.java

public static ShortBuffer createShortBuffer(final short... data) {
    if (data == null) {
        return null;
    }//from   ww  w  .ja v a 2 s.  c  o  m
    final ShortBuffer buff = createShortBuffer(data.length);
    buff.clear();
    buff.put(data);
    buff.flip();
    return buff;
}