Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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