Android ShortBuffer Create setupShortBuffer(ShortBuffer preBuffer, short[] array)

Here you can find the source of setupShortBuffer(ShortBuffer preBuffer, short[] array)

Description

setup Short Buffer

License

Open Source License

Declaration

public static ShortBuffer setupShortBuffer(ShortBuffer preBuffer,
            short[] array) 

Method Source Code

//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;
    }
}

Related

  1. buildShortBuffer(short[] buffer)
  2. asShortBuffer(short[] array)
  3. getShortBuffer(short[] list)
  4. toShortBuffer(short[] array)
  5. shotToBuffer(short[] a)
  6. wrap(short[] buffer)
  7. ConvToShortBuffer(short buf[])
  8. ConvToShortBuffer(short buf[])