Java IntBuffer Create newDirectIntBuffer(final int theSize)

Here you can find the source of newDirectIntBuffer(final int theSize)

Description

new Direct Int Buffer

License

Open Source License

Declaration

public static IntBuffer newDirectIntBuffer(final int theSize) 

Method Source Code

//package com.java2s;
/*/*from  ww w  .ja v  a2  s. co  m*/
 * Copyright (c) 2013 christianr.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v3
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-3.0.html
 * 
 * Contributors:
 *     christianr - initial API and implementation
 */

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import java.nio.IntBuffer;

public class Main {
    public static final int SIZE_OF_INT = 4;

    public static IntBuffer newDirectIntBuffer(final int theSize) {
        ByteBuffer myBuffer = ByteBuffer.allocateDirect(theSize
                * SIZE_OF_INT);
        myBuffer.order(ByteOrder.nativeOrder());
        return myBuffer.asIntBuffer();
    }

    public static IntBuffer newDirectIntBuffer(final int[] theData) {
        ByteBuffer myBuffer = ByteBuffer.allocateDirect(theData.length
                * SIZE_OF_INT);
        myBuffer.order(ByteOrder.nativeOrder());
        myBuffer.asIntBuffer().put(theData);
        myBuffer.rewind();
        return myBuffer.asIntBuffer();
    }
}

Related

  1. createIntBuffer(int size)
  2. createIntBuffer(int size)
  3. createIntBuffer(int... data)
  4. createIntBuffer(int[] array)
  5. createIntBufferOnHeap(final int size)
  6. newDirectIntBuffer(final int theSize)