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.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;

public class Main {

    public static FloatBuffer transportArrayToNativeBuffer(float[] fArray) {
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(fArray.length * 4);
        byteBuffer.order(ByteOrder.nativeOrder());
        return (FloatBuffer) byteBuffer.asFloatBuffer().put(fArray).position(0);
    }

    public static IntBuffer transportArrayToNativeBuffer(int[] iArray) {
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(iArray.length * 4);
        byteBuffer.order(ByteOrder.nativeOrder());
        return (IntBuffer) byteBuffer.asIntBuffer().put(iArray).position(0);
    }

    public static ShortBuffer transportArrayToNativeBuffer(short[] sArray) {
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(sArray.length * 2);
        byteBuffer.order(ByteOrder.nativeOrder());
        return (ShortBuffer) byteBuffer.asShortBuffer().put(sArray).position(0);
    }
}