create Short Buffer from short array - Android java.nio

Android examples for java.nio:ShortBuffer

Description

create Short Buffer from short array

Demo Code


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

import java.nio.ShortBuffer;

public class Main {
    public static ShortBuffer createShortBuffer(short[] shortData) {
        ShortBuffer drawListBuffer;
        ByteBuffer dlb = ByteBuffer.allocateDirect(
        // (# of coordinate values * 2 bytes per short)
                shortData.length * 2);//from   w ww.ja  v  a2  s .com
        dlb.order(ByteOrder.nativeOrder());
        drawListBuffer = dlb.asShortBuffer();
        drawListBuffer.put(shortData);
        drawListBuffer.position(0);
        return drawListBuffer;
    }
}

Related Tutorials