create And Init ShortBuffer - Android java.nio

Android examples for java.nio:ShortBuffer

Description

create And Init ShortBuffer

Demo Code


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

import java.nio.ShortBuffer;

public class Main {
    public static ShortBuffer createAndInitShortBuffer(short[] source) {
        if (source == null)
            return null;
        // short is 2 bytes, therefore we multiply the number if
        // vertices with 2.
        ByteBuffer indiceBiteBuffer = ByteBuffer
                .allocateDirect(source.length * 2);
        indiceBiteBuffer.order(ByteOrder.nativeOrder());
        ShortBuffer targetBuffer = indiceBiteBuffer.asShortBuffer();
        targetBuffer.put(source);/* w  w w  .ja  va  2 s  .c  om*/
        targetBuffer.position(0);
        return targetBuffer;
    }
}

Related Tutorials