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:info.gehrels.flockDBClient.ByteHelper.java

static ByteBuffer asByteBuffer(long... destinationIds) {
    ByteBuffer buf = null;/*from   ww w  .j  a  va  2s .c om*/
    buf = ByteBuffer.wrap(new byte[destinationIds.length * (Long.SIZE / 8)]);
    buf.order(ByteOrder.LITTLE_ENDIAN);
    for (long destinationId : destinationIds) {
        buf.putLong(destinationId);
    }
    buf.rewind();
    return buf;
}

From source file:org.mycontroller.standalone.uidtag.UidTagMapper.java

public static UidTagMapper get(String payload) throws DecoderException {
    UidTagStruct uidTagStruct = new UidTagStruct();
    uidTagStruct.setByteBuffer(//w  ww .  ja v a2  s  . c o m
            ByteBuffer.wrap(Hex.decodeHex(payload.toCharArray())).order(ByteOrder.LITTLE_ENDIAN), 0);
    return UidTagMapper.builder().uid(uidTagStruct.getPayload()).type(UIDQ_TYPE.get(uidTagStruct.getType()))
            .payload(String.valueOf(uidTagStruct.getPayload())).build();
}

From source file:info.gehrels.flockDBClient.ByteHelper.java

static long[] toLongArray(byte[] ids) {
    LongBuffer buffy = ByteBuffer.wrap(ids).order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
    long[] result = new long[buffy.capacity()];

    int i = 0;//w ww.  ja v a  2 s.  com
    while (buffy.hasRemaining()) {
        result[i++] = buffy.get();
    }

    return result;
}

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);
    }/* w  ww .  j ava 2 s.c om*/

    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;
}

From source file:mtmo.test.mediadrm.Utils.java

public static String accountIdToMarlinFormat(final String accountId) {
    ByteBuffer accountIdBuf = ByteBuffer.allocate(BYTES_OF_ACCOUNT_ID);
    try {/*from   w w  w . ja v  a2 s  .  co  m*/
        accountIdBuf.putLong(Long.valueOf(accountId));
    } catch (Exception e) {
        return null;
    }
    accountIdBuf.order(ByteOrder.LITTLE_ENDIAN);
    return String.format(Locale.US, "%016x", accountIdBuf.getLong(0));
}

From source file:Main.java

public static long findCentralDirStartOffset(final FileChannel fileChannel, final long commentLength)
        throws IOException {
    // End of central directory record (EOCD)
    // Offset    Bytes     Description[23]
    // 0           4       End of central directory signature = 0x06054b50
    // 4           2       Number of this disk
    // 6           2       Disk where central directory starts
    // 8           2       Number of central directory records on this disk
    // 10          2       Total number of central directory records
    // 12          4       Size of central directory (bytes)
    // 16          4       Offset of start of central directory, relative to start of archive
    // 20          2       Comment length (n)
    // 22          n       Comment
    // For a zip with no archive comment, the
    // end-of-central-directory record will be 22 bytes long, so
    // we expect to find the EOCD marker 22 bytes from the end.

    final ByteBuffer zipCentralDirectoryStart = ByteBuffer.allocate(4);
    zipCentralDirectoryStart.order(ByteOrder.LITTLE_ENDIAN);
    fileChannel.position(fileChannel.size() - commentLength - 6); // 6 = 2 (Comment length) + 4 (Offset of start of central directory, relative to start of archive)
    fileChannel.read(zipCentralDirectoryStart);
    final long centralDirStartOffset = zipCentralDirectoryStart.getInt(0);
    return centralDirStartOffset;
}

From source file:io.druid.segment.data.CompressedIntsIndexedWriterTest.java

@Parameterized.Parameters(name = "{index}: compression={0}, byteOrder={1}")
public static Iterable<Object[]> compressionStrategiesAndByteOrders() {
    Set<List<Object>> combinations = Sets.cartesianProduct(
            Sets.newHashSet(CompressedObjectStrategy.CompressionStrategy.noNoneValues()),
            Sets.newHashSet(ByteOrder.BIG_ENDIAN, ByteOrder.LITTLE_ENDIAN));

    return Iterables.transform(combinations, new Function<List, Object[]>() {
        @Override/* w w  w .jav  a2 s .  c o  m*/
        public Object[] apply(List input) {
            return new Object[] { input.get(0), input.get(1) };
        }
    });
}

From source file:org.dragonet.entity.metadata.type.ByteArrayMeta.java

@Override
public byte[] encode() {
    ByteBuffer buff = ByteBuffer.allocate(2 + this.data.length);
    buff.order(ByteOrder.LITTLE_ENDIAN);
    buff.putShort((short) (this.data.length & 0xFFFF));
    buff.put(this.data);
    return buff.array();
}

From source file:Main.java

/**
 * Parse UUID from bytes. The {@code uuidBytes} can represent a 16-bit, 32-bit or 128-bit UUID,
 * but the returned UUID is always in 128-bit format.
 * Note UUID is little endian in Bluetooth.
 *
 * @param uuidBytes Byte representation of uuid.
 * @return {@link ParcelUuid} parsed from bytes.
 * @throws IllegalArgumentException If the {@code uuidBytes} cannot be parsed.
 */// w ww. j a v a  2s . co m
public static ParcelUuid parseUuidFrom(byte[] uuidBytes) {
    if (uuidBytes == null) {
        throw new IllegalArgumentException("uuidBytes cannot be null");
    }
    int length = uuidBytes.length;
    if (length != UUID_BYTES_16_BIT && length != UUID_BYTES_32_BIT && length != UUID_BYTES_128_BIT) {
        throw new IllegalArgumentException("uuidBytes length invalid - " + length);
    }

    // Construct a 128 bit UUID.
    if (length == UUID_BYTES_128_BIT) {
        ByteBuffer buf = ByteBuffer.wrap(uuidBytes).order(ByteOrder.LITTLE_ENDIAN);
        long msb = buf.getLong(8);
        long lsb = buf.getLong(0);
        return new ParcelUuid(new UUID(msb, lsb));
    }

    // For 16 bit and 32 bit UUID we need to convert them to 128 bit value.
    // 128_bit_value = uuid * 2^96 + BASE_UUID
    long shortUuid;
    if (length == UUID_BYTES_16_BIT) {
        shortUuid = uuidBytes[0] & 0xFF;
        shortUuid += (uuidBytes[1] & 0xFF) << 8;
    } else {
        shortUuid = uuidBytes[0] & 0xFF;
        shortUuid += (uuidBytes[1] & 0xFF) << 8;
        shortUuid += (uuidBytes[2] & 0xFF) << 16;
        shortUuid += (uuidBytes[3] & 0xFF) << 24;
    }
    long msb = BASE_UUID.getUuid().getMostSignificantBits() + (shortUuid << 32);
    long lsb = BASE_UUID.getUuid().getLeastSignificantBits();
    return new ParcelUuid(new UUID(msb, lsb));
}

From source file:org.mycontroller.standalone.provider.mycontroller.structs.McCommon.java

@Override
public ByteOrder byteOrder() {
    return ByteOrder.LITTLE_ENDIAN;
}