Example usage for java.nio ByteOrder LITTLE_ENDIAN

List of usage examples for java.nio ByteOrder LITTLE_ENDIAN

Introduction

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

Prototype

ByteOrder LITTLE_ENDIAN

To view the source code for java.nio ByteOrder LITTLE_ENDIAN.

Click Source Link

Document

This constant represents little endian.

Usage

From source file:Main.java

private static IntBuffer newIntBuffer(int size) {
    ByteBuffer buffer = ByteBuffer.allocateDirect(size);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    return buffer.asIntBuffer();
}

From source file:Main.java

public static synchronized byte[] int16tobyte(int a) {
    byte[] inttemp = new byte[2];
    inttemp[1] = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(a).get(1);
    inttemp[0] = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(a).get(0);
    return inttemp;
}

From source file:Main.java

public static byte[] shortToByteArrayLE(short value) {
    ByteBuffer buffer = ByteBuffer.allocate(Short.SIZE / Byte.SIZE);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    buffer.putShort(value);//  www  .  j  a  va2 s  .  c o m
    return buffer.array();
}

From source file:Main.java

public static int fromArray(byte[] payload) {
    ByteBuffer buffer = ByteBuffer.wrap(payload);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    return buffer.getInt();
}

From source file:Main.java

public static byte[] downSample(final byte[] data) {
    final byte[] output = new byte[data.length / 2];
    int length = data.length;
    ByteBuffer bb = ByteBuffer.wrap(data);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    for (int i = 0; i < length; i += 2) {
        output[i / 2] = (byte) (((bb.getShort() * 128.0) / 32768.0) + 128.0);
    }/*from  ww  w .  j a v  a  2  s. co  m*/
    return output;
}

From source file:Main.java

public static int byteArrayToShort(byte[] bytes, int offset) {
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    return bb.getShort(offset);
}

From source file:Main.java

/**
 * Converts a given integer to byte, in little endian
 * @param i An integer to be converted to byte
 * @return A byte array stores byte representation of given integer
 *///from www .j a v  a  2s  .co  m
public static byte[] intToByte(int i) {
    ByteBuffer b = ByteBuffer.allocate(4);
    b.order(ByteOrder.LITTLE_ENDIAN);
    b.putInt(i);
    byte buf[] = b.array();
    return buf;
}

From source file:Main.java

public static int byteArrayToInt(byte[] bytes, int offset) {
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    return bb.getInt(offset);
}

From source file:Main.java

public static int readInt(InputStream inputStream) throws IOException {
    byte[] bytesToRead = new byte[4];
    inputStream.read(bytesToRead);/* ww w  .  j  a  v a  2  s. c  o  m*/

    ByteBuffer buffer = ByteBuffer.wrap(bytesToRead);
    buffer.order(ByteOrder.LITTLE_ENDIAN);

    return buffer.getInt();
}

From source file:Main.java

public static String bytesToUuid(byte[] bytes) {
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    bb.order(ByteOrder.LITTLE_ENDIAN);

    long lsb = bb.getLong();
    long msb = bb.getLong();
    UUID uuid = new UUID(msb, lsb);
    return uuidToString(uuid);
}