Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import java.nio.IntBuffer;

public class Main {
    public static Buffer setupIntBuffer(IntBuffer preBuffer, int[] array) {

        if (preBuffer == null || preBuffer.capacity() < array.length) {
            preBuffer = createIntBuffer(array.length * 2);
        } else {
            preBuffer.clear();
        }

        preBuffer.clear();
        preBuffer.put(array);
        preBuffer.position(0);

        return preBuffer;
    }

    public static IntBuffer createIntBuffer(int count) {
        ByteBuffer data = ByteBuffer.allocateDirect(count * 4);
        data.order(ByteOrder.nativeOrder());
        IntBuffer p1 = data.asIntBuffer();
        return p1;
    }
}