Here you can find the source of setupShortBuffer(ShortBuffer preBuffer, short[] array)
public static ShortBuffer setupShortBuffer(ShortBuffer preBuffer, short[] array)
//package com.java2s; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.ShortBuffer; public class Main { public static ShortBuffer setupShortBuffer(ShortBuffer preBuffer, short[] array) { if (preBuffer == null || preBuffer.capacity() < array.length) { preBuffer = createShortBuffer(array.length * 2); } else {/* w w w . ja va 2s. c o m*/ preBuffer.clear(); } preBuffer.clear(); preBuffer.put(array); preBuffer.position(0); return preBuffer; } public static ShortBuffer createShortBuffer(int shortCount) { ByteBuffer data = ByteBuffer.allocateDirect(shortCount * 4); data.order(ByteOrder.nativeOrder()); ShortBuffer p1 = data.asShortBuffer(); return p1; } }