make ShortBuffer - Android java.nio

Android examples for java.nio:ShortBuffer

Description

make ShortBuffer

Demo Code


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

import java.nio.ShortBuffer;

public class Main {
    public static ShortBuffer makeShortBuffer(short[] arr) {
        ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 2);
        bb.order(ByteOrder.nativeOrder());
        ShortBuffer sb = bb.asShortBuffer();
        sb.put(arr);/*w  ww .  jav a2  s  .  c  o m*/
        sb.position(0);
        return sb;
    }
}

Related Tutorials