build Short Buffer - Java java.nio

Java examples for java.nio:ShortBuffer

Description

build Short Buffer

Demo Code


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

import java.nio.ShortBuffer;

public class Main {
    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  w w  w .  j a  v  a 2 s. co  m*/
        buffer.position(0);
        return buffer;
    }
}

Related Tutorials