Example usage for java.nio ByteOrder nativeOrder

List of usage examples for java.nio ByteOrder nativeOrder

Introduction

In this page you can find the example usage for java.nio ByteOrder nativeOrder.

Prototype

public static ByteOrder nativeOrder() 

Source Link

Document

Returns the current platform byte order.

Usage

From source file:Main.java

public static boolean testCPU() {
    if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
        return true;
    } else {/*  w  ww .j ava2 s  .  c o  m*/
        return false;
    }
}

From source file:Main.java

/**
 * Allocates a direct float buffer, and populates it with the float array data.
 *//*from w w w.  ja  v  a  2  s .c  om*/
public static FloatBuffer createFloatBuffer(float[] coords) {
    // Allocate a direct ByteBuffer, using 4 bytes per float, and copy coords into it.
    ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * SIZEOF_FLOAT);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    fb.put(coords);
    fb.position(0);
    return fb;
}

From source file:Main.java

public static ByteBuffer newByteBuffer(int numElements) {
    ByteBuffer bb = ByteBuffer.allocateDirect(numElements);
    bb.order(ByteOrder.nativeOrder());
    return bb;/*  w  ww .  jav  a 2s . c  o m*/
}

From source file:Main.java

static private void ensureSize(int n) {
    if (buffer.capacity() < n) {
        buffer = ByteBuffer.allocateDirect(n).order(ByteOrder.nativeOrder());
        bufferInt = buffer.asIntBuffer();
        bufferFloat = buffer.asFloatBuffer();
    }/*w w  w. j  av a 2  s . co m*/
}

From source file:Main.java

public static IntBuffer createIntBuffer(final int size) {
    final IntBuffer buf = ByteBuffer.allocateDirect(SIZEOF_FLOAT * size).order(ByteOrder.nativeOrder())
            .asIntBuffer();//from  w  w w .ja  v  a 2s  .co  m
    buf.clear();
    return buf;
}

From source file:Main.java

/**android methods*/

//Only for Android
public static IntBuffer makeFloatBuffer(int[] array) {
    final int integerSize = Integer.SIZE / 8;
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length * integerSize);
    byteBuffer.order(ByteOrder.nativeOrder());
    IntBuffer intBuffer = byteBuffer.asIntBuffer();
    intBuffer.put(array);//from   w ww. j av  a  2 s.co m
    intBuffer.position(0);
    return intBuffer;
}

From source file:de.ailis.threedee.utils.BufferUtils.java

/**
 * Creates a direct byte buffer with native byte order.
 *
 * @param size/*from  w w  w. ja v  a  2s  . co m*/
 *            The data
 * @return The created direct byte buffer
 */

public static ByteBuffer createDirectByteBuffer(final int size) {
    return ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
}

From source file:Main.java

public static FloatBuffer makeFloatBuffer(float[] array) {
    final int floatSize = Float.SIZE / 8;
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length * floatSize);
    byteBuffer.order(ByteOrder.nativeOrder());
    FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
    floatBuffer.put(array);//from w  w w . j av a 2s  .c om
    floatBuffer.position(0);
    return floatBuffer;
}

From source file:BufferTest.java

private void run() {
    final int size = 100000;

    bb = ByteBuffer.allocateDirect(4 * size).order(ByteOrder.nativeOrder());
    floats = bb.asFloatBuffer();//  w ww.j a  v a  2 s.c  o  m

    data = data(size);

    System.out.println("# size\tsingle\tindexed\tbatch");

    int base = 0;

    int e = size;
    while (base + e > 100) {
        test(base + e);
        e /= 2;
    }
}

From source file:org.namelessrom.devicecontrol.net.NetworkInfo.java

public static String getWifiIp() {
    final WifiManager wifiManager = (WifiManager) Application.get().getSystemService(Context.WIFI_SERVICE);
    int ipAddress = wifiManager.getConnectionInfo().getIpAddress();
    if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) {
        ipAddress = Integer.reverseBytes(ipAddress);
    }//from w ww.j a v  a  2  s. c o m

    final byte[] ipByteArray = BigInteger.valueOf(ipAddress).toByteArray();

    String ipAddressString;
    try {
        ipAddressString = InetAddress.getByAddress(ipByteArray).getHostAddress();
    } catch (UnknownHostException ex) {
        ipAddressString = "0.0.0.0";
    }

    return ipAddressString;
}