Java Code Examples for java.util.UUID#getMostSignificantBits()

The following examples show how to use java.util.UUID#getMostSignificantBits() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Uuid.java    From terracotta-platform with Apache License 2.0 6 votes vote down vote up
static String generateShortUuid() {
  UUID uuid = UUID.randomUUID();
  byte[] data = new byte[16];
  long msb = uuid.getMostSignificantBits();
  long lsb = uuid.getLeastSignificantBits();
  for (int i = 0; i < 8; i++) {
    data[i] = (byte) (msb & 0xff);
    msb >>>= 8;
  }
  for (int i = 8; i < 16; i++) {
    data[i] = (byte) (lsb & 0xff);
    lsb >>>= 8;
  }
  return Base64.getEncoder().encodeToString(data)
      // java-8 and other - compatible B64 url decoder use - and _ instead of + and /
      // padding can be ignored to shorten the UUID
      .replace('+', '-')
      .replace('/', '_')
      .replace("=", "");
}
 
Example 2
Source File: CodecSupport.java    From journalkeeper with Apache License 2.0 5 votes vote down vote up
public static void encodeUUID(ByteBuf byteBuf, UUID uuid) {
    long mostSigBits = 0L;
    long leastSigBits = 0L;

    if (null != uuid) {
        mostSigBits = uuid.getMostSignificantBits();
        leastSigBits = uuid.getLeastSignificantBits();
    }
    encodeLong(byteBuf, mostSigBits);
    encodeLong(byteBuf, leastSigBits);
}
 
Example 3
Source File: BinaryEncoder.java    From opc-ua-stack with Apache License 2.0 5 votes vote down vote up
@Override
public void encodeGuid(String field, UUID value) {
    if (value == null) {
        buffer.writeZero(16);
    } else {
        long msb = value.getMostSignificantBits();
        long lsb = value.getLeastSignificantBits();

        buffer.writeInt((int) (msb >>> 32));
        buffer.writeShort((int) (msb >>> 16) & 0xFFFF);
        buffer.writeShort((int) (msb) & 0xFFFF);

        buffer.order(ByteOrder.BIG_ENDIAN).writeLong(lsb);
    }
}
 
Example 4
Source File: AbstractEncoder.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public void writeUuid(UUID uuid)
{
    long msb = 0;
    long lsb = 0;
    if (uuid != null)
    {
        msb = uuid.getMostSignificantBits();
        lsb = uuid.getLeastSignificantBits();
    }
    writeUint64(msb);
    writeUint64(lsb);
}
 
Example 5
Source File: BluetoothUuid.java    From EFRConnect-android with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given parcelUuid can be converted to 32 bit bluetooth uuid.
 *
 * @param parcelUuid
 * @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);
}
 
Example 6
Source File: BluetoothUuid.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given parcelUuid can be converted to 32 bit bluetooth uuid.
 *
 * @param parcelUuid
 * @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);
}
 
Example 7
Source File: BleScanInfo.java    From AsteroidOSSync with GNU General Public License v3.0 5 votes vote down vote up
private static boolean shortUuid(UUID u)
{
    long msb = u.getMostSignificantBits();
    short m = (short) (msb >>> 32);
    UUID test = Uuids.fromShort(Utils_Byte.bytesToHexString(Utils_Byte.shortToBytes(m)));
    return test.equals(u);
}
 
Example 8
Source File: UUIDSerializer.java    From xson with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Object target, WriterModel model) {
	UUID x = (UUID) target;
	long mostSigBits = x.getMostSignificantBits();
	long leastSigBits = x.getLeastSignificantBits();
	model.writeByte1(XsonConst.UUID_WRAP);
	model.writeLong(mostSigBits);
	model.writeLong(leastSigBits);
}
 
Example 9
Source File: UUIDUtils.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
public static byte[] toBytes(UUID id) {
    Preconditions.checkNotNull(id, "Null id");
    byte[] result = new byte[16];
    long lsb = id.getLeastSignificantBits();
    for (int i = 15; i >= 8; i--) {
        result[i] = (byte) (lsb & 0xffL);
        lsb >>= 8;
    }
    long msb = id.getMostSignificantBits();
    for (int i = 7; i >= 0; i--) {
        result[i] = (byte) (msb & 0xffL);
        msb >>= 8;
    }
    return result;
}
 
Example 10
Source File: UUIDs.java    From emodb with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the byte-array equivalent of the specified UUID in big-endian order.
 */
public static byte[] asByteArray(UUID uuid) {
    long msb = uuid.getMostSignificantBits();
    long lsb = uuid.getLeastSignificantBits();
    byte[] buf = new byte[16];
    for (int i = 0; i < 8; i++) {
        buf[i]     = (byte) (msb >>> 8 * (7 - i));
        buf[i + 8] = (byte) (lsb >>> 8 * (7 - i));
    }
    return buf;
}
 
Example 11
Source File: UUIDTypeTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimeEquality()
{
    UUID a = UUIDGen.getTimeUUID();
    UUID b = new UUID(a.getMostSignificantBits(),
            a.getLeastSignificantBits());

    assertEquals(0, uuidType.compare(bytebuffer(a), bytebuffer(b)));
}
 
Example 12
Source File: JobMasterId.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a JobMasterId that takes the bits from the given UUID.
 */
public JobMasterId(UUID uuid) {
	super(uuid.getLeastSignificantBits(), uuid.getMostSignificantBits());
}
 
Example 13
Source File: SimpleTabEntry.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
protected static UUID randomUUIDVersion2() {
    UUID uuid = UUID.randomUUID();
    return new UUID((uuid.getMostSignificantBits() & ~0xf000) | 0x2000, uuid.getLeastSignificantBits());
}
 
Example 14
Source File: PithosHandleFactory.java    From hypergraphdb with Apache License 2.0 4 votes vote down vote up
public UPHandle makeHandle(byte[] buffer)
{
	UUID uuid = UUID.nameUUIDFromBytes(buffer);
	return new UPHandle(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
}
 
Example 15
Source File: UuidUtil.java    From Rhombus with MIT License 4 votes vote down vote up
/**
 * Retrieve the integer name from a namespace uuid generated using this class
 * @param uuid UUID generated using
 * @return Name retrieved from the UUID
 */
public static Long nameFromUUID(UUID uuid) {
       char msb = (char)((uuid.getMostSignificantBits() >>> 16) & 0xffff);
       long out = uuid.getLeastSignificantBits() & 0xffffffffffffL;
       return out | ((long)msb << 48);
}
 
Example 16
Source File: FidoServerAttestationOptionsEndpointFilter.java    From webauthn4j-spring-security with Apache License 2.0 4 votes vote down vote up
private byte[] generateUserHandle() {
    UUID uuid = UUID.randomUUID();
    long hi = uuid.getMostSignificantBits();
    long lo = uuid.getLeastSignificantBits();
    return ByteBuffer.allocate(16).putLong(hi).putLong(lo).array();
}
 
Example 17
Source File: BleSpecs.java    From attach with GNU General Public License v3.0 4 votes vote down vote up
public static long getAssignedNumber(UUID uuid) {
    return (uuid.getMostSignificantBits() & 0x0000FFFF00000000L) >> 32;
}
 
Example 18
Source File: IntermediateDataSetID.java    From Flink-CEPplus with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new intermediate data set ID with the bytes of the given UUID.
 * 
 * @param from The UUID to create this ID from.
 */
public IntermediateDataSetID(UUID from) {
	super(from.getLeastSignificantBits(), from.getMostSignificantBits());
}
 
Example 19
Source File: BLENodeDefines.java    From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * extract the fist 32 bits from the characteristics UUID
 *
 * @param uuid characteristics uuid
 * @return feature mask bit, the first 32 bit of the UUID
 */
public static int extractFeatureMask(UUID uuid) {
    return (int) (uuid.getMostSignificantBits() >> 32);
}
 
Example 20
Source File: IntermediateDataSetID.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new intermediate data set ID with the bytes of the given UUID.
 *
 * @param from The UUID to create this ID from.
 */
public IntermediateDataSetID(UUID from) {
	super(from.getLeastSignificantBits(), from.getMostSignificantBits());
}