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 void main(String args[]) {
    ByteOrder b = ByteOrder.nativeOrder();

    if (b.equals(ByteOrder.BIG_ENDIAN)) {
        System.out.println("Big endian");
    } else {/* w  ww .j  a  v  a 2s . c  o  m*/

        System.out.println("Little  endian");
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ByteBuffer bbuf = ByteBuffer.allocate(10);
    int capacity = bbuf.capacity(); // 10
    System.out.println(capacity);

    bbuf.order(ByteOrder.nativeOrder());

    bbuf.put("java2s.com".getBytes());

    System.out.println(Arrays.toString(bbuf.array()));
}

From source file:net.egelke.chrome.eid.Main.java

public static void main(String[] args) throws Throwable {
    try {/* w w w .j  a  va 2s  .  com*/
        logger.debug("Start native eid process");
        bb.order(ByteOrder.nativeOrder());
        mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);

        Message input;
        do {
            input = nextMessage();
            Message output = new Message();
            output.setType(Message.Type.EID_OUTPUT);

            //TODO:others
            if (input.getAction() instanceof StartAction) {
                output.setAction(input.getAction());
            } else {
                throw new UnsupportedOperationException();
            }

            respond(output);
        } while (!(input.getAction() instanceof EndAction));

        logger.debug("End native eid process");
    } catch (Throwable e) {
        logger.error("Fatal error", e);
        throw e;
    }
}

From source file:Main.java

public static ByteBuffer createByteBuffer(int count) {
    ByteBuffer data = ByteBuffer.allocateDirect(count * 4);
    data.order(ByteOrder.nativeOrder());
    return data;//w ww  . j  a  v  a2 s  .  com
}

From source file:Main.java

public static FloatBuffer FloatToBuffer(float[] array) {
    FloatBuffer fb = ByteBuffer.allocateDirect(array.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();

    fb.put(array).position(0);//from  www  .j  a v  a 2s. co m

    return fb;
}

From source file:Main.java

public static FloatBuffer arrayToBuffer(float[] arr) {
    FloatBuffer buffer = ByteBuffer.allocateDirect(arr.length * 4).order(ByteOrder.nativeOrder())
            .asFloatBuffer();//ww  w. j ava 2 s.c om
    buffer.put(arr).position(0);
    return buffer;
}

From source file:Main.java

public static IntBuffer getBufferFromIntArray(int[] array) {
    IntBuffer result = ByteBuffer.allocateDirect(array.length * 4).order(ByteOrder.nativeOrder()).asIntBuffer();
    result.put(array).position(0);/* www .java 2s.co m*/
    return result;
}

From source file:Main.java

public static IntBuffer getIntBuffer(int[] coords) {
    ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * 4);
    bb.order(ByteOrder.nativeOrder());
    IntBuffer intBuffer = bb.asIntBuffer();
    intBuffer.put(coords);/*from   www  .  j a  v  a 2  s  . co m*/
    intBuffer.position(0);
    return intBuffer;
}

From source file:Main.java

public static FloatBuffer makeFloatBuffer(int i_len) {
    ByteBuffer bb = ByteBuffer.allocateDirect(i_len * 4);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    fb.position(0);//from w  w  w  .ja v a  2s .c  om
    return fb;
}

From source file:Main.java

public static FloatBuffer getBufferFromFloatArray(float[] array) {
    FloatBuffer result = ByteBuffer.allocateDirect(array.length * 4).order(ByteOrder.nativeOrder())
            .asFloatBuffer();//  www . j av a  2 s. c  o m
    result.put(array).position(0);
    return result;
}