List of usage examples for java.util UUID getLeastSignificantBits
public long getLeastSignificantBits()
From source file:Main.java
public static void main(String[] args) { // creating UUID UUID uid = UUID.randomUUID(); // checking least significant bits System.out.println("Least significant bits: " + uid.getLeastSignificantBits()); }
From source file:Main.java
/** * Check whether the given parcelUuid can be converted to 16 bit bluetooth uuid. * * @param parcelUuid// w ww . j av a2 s . co m * @return true if the parcelUuid can be converted to 16 bit uuid, false otherwise. */ public static boolean is16BitUuid(ParcelUuid parcelUuid) { UUID uuid = parcelUuid.getUuid(); if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) { return false; } return ((uuid.getMostSignificantBits() & 0xFFFF0000FFFFFFFFL) == 0x1000L); }
From source file:Main.java
/** * Check whether the given parcelUuid can be converted to 32 bit bluetooth uuid. * * @param parcelUuid/*from w w w .j a v a 2 s . co m*/ * @return true if the parcelUuid can be converted to 32 bit uuid, false otherwise. */ public static boolean is32BitUuid(ParcelUuid parcelUuid) { UUID uuid = parcelUuid.getUuid(); if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) { return false; } if (is16BitUuid(parcelUuid)) { return false; } return ((uuid.getMostSignificantBits() & 0xFFFFFFFFL) == 0x1000L); }
From source file:Main.java
public static byte[] randomUUID() { UUID uuid = UUID.randomUUID(); long hi = uuid.getMostSignificantBits(); long lo = uuid.getLeastSignificantBits(); return ByteBuffer.allocate(16).putLong(hi).putLong(lo).array(); }
From source file:Main.java
/** * Check if the specified UUID style is short style. * * @param src the UUID//from w w w . ja v a 2s .c om * @return true if the UUID is short style */ private static boolean isShortUuid(@NonNull final UUID src) { return (src.getMostSignificantBits() & 0xffff0000ffffffffL) == 0L && src.getLeastSignificantBits() == 0L; }
From source file:Main.java
public static byte[] uuidToByteArray(UUID uuid) { long msb = uuid.getMostSignificantBits(); long lsb = uuid.getLeastSignificantBits(); byte[] buffer = new byte[16]; for (int i = 0; i < 8; i++) { buffer[i] = (byte) (msb >>> 8 * (7 - i)); }/* www . ja va 2 s .co m*/ for (int i = 8; i < 16; i++) { buffer[i] = (byte) (lsb >>> 8 * (7 - i)); } return buffer; }
From source file:Main.java
/** * Check if the specified UUID style is short style. * * @param src the UUID/* w ww . j a v a 2 s. co m*/ * @return true if the UUID is short style */ private static boolean isShortUuid(@NonNull final UUID src) { return ((src.getMostSignificantBits() & 0xffff0000ffffffffL) == 0L) && (src.getLeastSignificantBits() == 0L); }
From source file:de.undercouch.bson4jackson.serializers.BsonUuidSerializer.java
/** * Utility routine for converting UUIDs to bytes in little endian format. * @param uuid The UUID to convert/*from ww w .ja v a2 s . c o m*/ * @return a byte array representing the UUID in little endian format */ private static byte[] uuidToLittleEndianBytes(UUID uuid) { long msb = uuid.getMostSignificantBits(); long lsb = uuid.getLeastSignificantBits(); byte[] buffer = new byte[16]; for (int i = 0; i < 8; i++) { buffer[i] = (byte) (msb >>> 8 * i); } for (int i = 8; i < 16; i++) { buffer[i] = (byte) (lsb >>> 8 * (i - 16)); } return buffer; }
From source file:org.zht.framework.uuid.Base64UuidGenerator.java
private static String base64Uuid(UUID uuid) { ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return Base64.encodeBase64URLSafeString(bb.array()); }
From source file:com.images3.data.impl.ShortUUID.java
private static byte[] toByteArray(UUID uuid) { ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return bb.array(); }