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 makeShortBuffer(short[] array) {
        if (array == null)
            throw new IllegalArgumentException();

        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(2 * array.length);
        byteBuffer.order(ByteOrder.nativeOrder());
        ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
        shortBuffer.put(array);
        shortBuffer.position(0);
        return shortBuffer;
    }
}