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

The following examples show how to use java.util.UUID#getLeastSignificantBits() . 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: TradeCompaniesDMLStmt.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static byte[] getUidBytes(UUID uuid){
  /*
  byte[] bytes = new byte[uidLength];
  rand.nextBytes(bytes);
  return bytes;
  */
  if (uuid == null) return null;
  long[] longArray = new long[2];
  longArray[0] = uuid.getMostSignificantBits();
  longArray[1] = uuid.getLeastSignificantBits();

  byte[] bytes = new byte[uidLength];
  ByteBuffer bb = ByteBuffer.wrap(bytes);
  bb.putLong(longArray[0]);
  bb.putLong(longArray[1]);
  return bytes;
}
 
Example 2
Source File: SchemaUtils.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Transform an UUID in a byte array
 * @param uuid The UUID to transform
 * @return The byte[] representing the UUID
 */
public static byte[] uuidToBytes( UUID uuid )
{
    Long low = uuid.getLeastSignificantBits();
    Long high = uuid.getMostSignificantBits();
    byte[] bytes = new byte[16];

    bytes[0] = ( byte ) ( ( high & 0xff00000000000000L ) >> 56 );
    bytes[1] = ( byte ) ( ( high & 0x00ff000000000000L ) >> 48 );
    bytes[2] = ( byte ) ( ( high & 0x0000ff0000000000L ) >> 40 );
    bytes[3] = ( byte ) ( ( high & 0x000000ff00000000L ) >> 32 );
    bytes[4] = ( byte ) ( ( high & 0x00000000ff000000L ) >> 24 );
    bytes[5] = ( byte ) ( ( high & 0x0000000000ff0000L ) >> 16 );
    bytes[6] = ( byte ) ( ( high & 0x000000000000ff00L ) >> 8 );
    bytes[7] = ( byte ) ( high & 0x00000000000000ffL );
    bytes[8] = ( byte ) ( ( low & 0xff00000000000000L ) >> 56 );
    bytes[9] = ( byte ) ( ( low & 0x00ff000000000000L ) >> 48 );
    bytes[10] = ( byte ) ( ( low & 0x0000ff0000000000L ) >> 40 );
    bytes[11] = ( byte ) ( ( low & 0x000000ff00000000L ) >> 32 );
    bytes[12] = ( byte ) ( ( low & 0x00000000ff000000L ) >> 24 );
    bytes[13] = ( byte ) ( ( low & 0x0000000000ff0000L ) >> 16 );
    bytes[14] = ( byte ) ( ( low & 0x000000000000ff00L ) >> 8 );
    bytes[15] = ( byte ) ( low & 0x00000000000000ffL );

    return bytes;
}
 
Example 3
Source File: Address.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
private static void writeUUID(UUID source, byte[] dest, int offset) {
   long msb = source.getMostSignificantBits();
   long lsb = source.getLeastSignificantBits();
   dest[offset]    = (byte) ((msb >> 56) & 0xff);
   dest[offset+1]  = (byte) ((msb >> 48) & 0xff);
   dest[offset+2]  = (byte) ((msb >> 40) & 0xff);
   dest[offset+3]  = (byte) ((msb >> 32) & 0xff);
   dest[offset+4]  = (byte) ((msb >> 24) & 0xff);
   dest[offset+5]  = (byte) ((msb >> 16) & 0xff);
   dest[offset+6]  = (byte) ((msb >> 8) & 0xff);
   dest[offset+7]  = (byte) (msb & 0xff);
   dest[offset+8]  = (byte) ((lsb >> 56) & 0xff);
   dest[offset+9]  = (byte) ((lsb >> 48) & 0xff);
   dest[offset+10] = (byte) ((lsb >> 40) & 0xff);
   dest[offset+11] = (byte) ((lsb >> 32) & 0xff);
   dest[offset+12] = (byte) ((lsb >> 24) & 0xff);
   dest[offset+13] = (byte) ((lsb >> 16) & 0xff);
   dest[offset+14] = (byte) ((lsb >> 8) & 0xff);
   dest[offset+15] = (byte) (lsb & 0xff);
   // 4 additional reserved bytes
   dest[offset+16] = dest[offset+17] = dest[offset+18] = dest[offset+19] = 0;
}
 
Example 4
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 16 bit bluetooth uuid.
 *
 * @param parcelUuid
 * @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);
}
 
Example 5
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 6
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 7
Source File: DigestUtils.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
public UUID deriveUUID(UUID base, long maskLow, long maskHigh)
{
	long baseMostSig = base.getMostSignificantBits();
	long baseLeastSig = base.getLeastSignificantBits();
	
	return new UUID(
			baseMostSig ^ (maskLow & 0xffffffffffff0fffl),//preserve version 
			baseLeastSig ^ (maskHigh & 0x3fffffffffffffffl)//preserve variant
			);
}
 
Example 8
Source File: IBeacon.java    From nv-bluetooth with Apache License 2.0 5 votes vote down vote up
/**
 * Set the proximity UUID.
 *
 *
 * @param uuid
 *         The proximity UUID. The value must not be {@code null}.
 *
 * @throws IllegalArgumentException
 *         The given value is {@code null}.
 */
public void setUUID(UUID uuid)
{
    if (uuid == null)
    {
        throw new IllegalArgumentException("'uuid' is null.");
    }

    mUUID = uuid;

    long msbits = uuid.getMostSignificantBits();
    long lsbits = uuid.getLeastSignificantBits();

    byte[] data = getData();
    data[UUID_INDEX +  0] = (byte)((msbits >> 56) & 0xFF);
    data[UUID_INDEX +  1] = (byte)((msbits >> 48) & 0xFF);
    data[UUID_INDEX +  2] = (byte)((msbits >> 40) & 0xFF);
    data[UUID_INDEX +  3] = (byte)((msbits >> 32) & 0xFF);
    data[UUID_INDEX +  4] = (byte)((msbits >> 24) & 0xFF);
    data[UUID_INDEX +  5] = (byte)((msbits >> 16) & 0xFF);
    data[UUID_INDEX +  6] = (byte)((msbits >>  8) & 0xFF);
    data[UUID_INDEX +  7] = (byte)((msbits      ) & 0xFF);
    data[UUID_INDEX +  8] = (byte)((lsbits >> 56) & 0xFF);
    data[UUID_INDEX +  9] = (byte)((lsbits >> 48) & 0xFF);
    data[UUID_INDEX + 10] = (byte)((lsbits >> 40) & 0xFF);
    data[UUID_INDEX + 11] = (byte)((lsbits >> 32) & 0xFF);
    data[UUID_INDEX + 12] = (byte)((lsbits >> 24) & 0xFF);
    data[UUID_INDEX + 13] = (byte)((lsbits >> 16) & 0xFF);
    data[UUID_INDEX + 14] = (byte)((lsbits >>  8) & 0xFF);
    data[UUID_INDEX + 15] = (byte)((lsbits >>  0) & 0xFF);
}
 
Example 9
Source File: XpmImageParser.java    From commons-imaging with Apache License 2.0 5 votes vote down vote up
private String randomName() {
    final UUID uuid = UUID.randomUUID();
    final StringBuilder stringBuilder = new StringBuilder("a");
    long bits = uuid.getMostSignificantBits();
    // Long.toHexString() breaks for very big numbers
    for (int i = 64 - 8; i >= 0; i -= 8) {
        stringBuilder.append(Integer.toHexString((int) ((bits >> i) & 0xff)));
    }
    bits = uuid.getLeastSignificantBits();
    for (int i = 64 - 8; i >= 0; i -= 8) {
        stringBuilder.append(Integer.toHexString((int) ((bits >> i) & 0xff)));
    }
    return stringBuilder.toString();
}
 
Example 10
Source File: DocumentBuilder.java    From modernmt with Apache License 2.0 5 votes vote down vote up
public static Query makeOwnerMatchingQuery(UUID owner) {
    long msb = (owner != null) ? owner.getMostSignificantBits() : 0L;
    long lsb = (owner != null) ? owner.getLeastSignificantBits() : 0L;

    Term msbTerm = makeLongTerm(msb, OWNER_MSB_FIELD);
    Term lsbTerm = makeLongTerm(lsb, OWNER_LSB_FIELD);

    BooleanQuery query = new BooleanQuery();
    query.add(new TermQuery(msbTerm), BooleanClause.Occur.MUST);
    query.add(new TermQuery(lsbTerm), BooleanClause.Occur.MUST);
    return query;
}
 
Example 11
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 12
Source File: IDUtils.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
private static String buildLiteId(int length, String chars) {
    UUID uuid = UUID.randomUUID();
    long high = uuid.getMostSignificantBits();
    long low = uuid.getLeastSignificantBits();

    int offset = 128 / length;
    int dcLength = chars.length();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < length; i++) {
        long v = DigitUtils.sub(high, low, offset * i, offset);
        sb.append(chars.charAt(DigitUtils.mod(v, dcLength)));
    }
    return sb.toString();
}
 
Example 13
Source File: UUIDSerializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private final static byte[] _asBytes(UUID uuid)
{
    byte[] buffer = new byte[16];
    long hi = uuid.getMostSignificantBits();
    long lo = uuid.getLeastSignificantBits();
    _appendInt((int) (hi >> 32), buffer, 0);
    _appendInt((int) hi, buffer, 4);
    _appendInt((int) (lo >> 32), buffer, 8);
    _appendInt((int) lo, buffer, 12);
    return buffer;
}
 
Example 14
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 15
Source File: JobMasterId.java    From Flink-CEPplus 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 16
Source File: ReceiveChannelEndpointThreadLocals.java    From aeron with Apache License 2.0 4 votes vote down vote up
public ReceiveChannelEndpointThreadLocals()
{
    final int smLength = StatusMessageFlyweight.HEADER_LENGTH + SIZE_OF_LONG;
    final int bufferLength =
        BitUtil.align(smLength, CACHE_LINE_LENGTH) +
        BitUtil.align(NakFlyweight.HEADER_LENGTH, CACHE_LINE_LENGTH) +
        BitUtil.align(RttMeasurementFlyweight.HEADER_LENGTH, CACHE_LINE_LENGTH);

    final UUID uuid = UUID.randomUUID();
    nextReceiverId = uuid.getMostSignificantBits() ^ uuid.getLeastSignificantBits();

    final ByteBuffer byteBuffer = BufferUtil.allocateDirectAligned(bufferLength, CACHE_LINE_LENGTH);

    byteBuffer.limit(smLength);
    smBuffer = byteBuffer.slice();
    statusMessageFlyweight = new StatusMessageFlyweight(smBuffer);

    final int nakMessageOffset = BitUtil.align(smLength, FRAME_ALIGNMENT);
    byteBuffer.limit(nakMessageOffset + NakFlyweight.HEADER_LENGTH).position(nakMessageOffset);
    nakBuffer = byteBuffer.slice();
    nakFlyweight = new NakFlyweight(nakBuffer);

    final int rttMeasurementOffset = nakMessageOffset + BitUtil.align(NakFlyweight.HEADER_LENGTH, FRAME_ALIGNMENT);
    byteBuffer.limit(rttMeasurementOffset + RttMeasurementFlyweight.HEADER_LENGTH).position(rttMeasurementOffset);
    rttMeasurementBuffer = byteBuffer.slice();
    rttMeasurementFlyweight = new RttMeasurementFlyweight(rttMeasurementBuffer);

    statusMessageFlyweight
        .version(HeaderFlyweight.CURRENT_VERSION)
        .headerType(HeaderFlyweight.HDR_TYPE_SM)
        .frameLength(StatusMessageFlyweight.HEADER_LENGTH);

    nakFlyweight
        .version(HeaderFlyweight.CURRENT_VERSION)
        .headerType(HeaderFlyweight.HDR_TYPE_NAK)
        .frameLength(NakFlyweight.HEADER_LENGTH);

    rttMeasurementFlyweight
        .version(HeaderFlyweight.CURRENT_VERSION)
        .headerType(HeaderFlyweight.HDR_TYPE_RTTM)
        .frameLength(RttMeasurementFlyweight.HEADER_LENGTH);
}
 
Example 17
Source File: TUUID.java    From rapidoid with Apache License 2.0 4 votes vote down vote up
public TUUID() {
	UUID uuid = UUID.randomUUID();
	this.time = U.time();
	this.uuidHigh = uuid.getMostSignificantBits();
	this.uuidLow = uuid.getLeastSignificantBits();
}
 
Example 18
Source File: FastUUID.java    From fast-uuid with MIT License 4 votes vote down vote up
/**
 * Returns a string representation of the given UUID. The returned string is formatted as described in
 * {@link UUID#toString()}.
 *
 * @param uuid the UUID to represent as a string
 *
 * @return a string representation of the given UUID
 */
public static String toString(final UUID uuid) {
    if (USE_JDK_UUID_TO_STRING) {
        // OpenJDK 9 and newer use a fancy native approach to converting UUIDs to strings and we're better off using
        // that if it's available.
        return uuid.toString();
    }

    final long mostSignificantBits = uuid.getMostSignificantBits();
    final long leastSignificantBits = uuid.getLeastSignificantBits();

    final char[] uuidChars = new char[UUID_STRING_LENGTH];

    uuidChars[0]  = HEX_DIGITS[(int) ((mostSignificantBits & 0xf000000000000000L) >>> 60)];
    uuidChars[1]  = HEX_DIGITS[(int) ((mostSignificantBits & 0x0f00000000000000L) >>> 56)];
    uuidChars[2]  = HEX_DIGITS[(int) ((mostSignificantBits & 0x00f0000000000000L) >>> 52)];
    uuidChars[3]  = HEX_DIGITS[(int) ((mostSignificantBits & 0x000f000000000000L) >>> 48)];
    uuidChars[4]  = HEX_DIGITS[(int) ((mostSignificantBits & 0x0000f00000000000L) >>> 44)];
    uuidChars[5]  = HEX_DIGITS[(int) ((mostSignificantBits & 0x00000f0000000000L) >>> 40)];
    uuidChars[6]  = HEX_DIGITS[(int) ((mostSignificantBits & 0x000000f000000000L) >>> 36)];
    uuidChars[7]  = HEX_DIGITS[(int) ((mostSignificantBits & 0x0000000f00000000L) >>> 32)];
    uuidChars[8]  = '-';
    uuidChars[9]  = HEX_DIGITS[(int) ((mostSignificantBits & 0x00000000f0000000L) >>> 28)];
    uuidChars[10] = HEX_DIGITS[(int) ((mostSignificantBits & 0x000000000f000000L) >>> 24)];
    uuidChars[11] = HEX_DIGITS[(int) ((mostSignificantBits & 0x0000000000f00000L) >>> 20)];
    uuidChars[12] = HEX_DIGITS[(int) ((mostSignificantBits & 0x00000000000f0000L) >>> 16)];
    uuidChars[13] = '-';
    uuidChars[14] = HEX_DIGITS[(int) ((mostSignificantBits & 0x000000000000f000L) >>> 12)];
    uuidChars[15] = HEX_DIGITS[(int) ((mostSignificantBits & 0x0000000000000f00L) >>> 8)];
    uuidChars[16] = HEX_DIGITS[(int) ((mostSignificantBits & 0x00000000000000f0L) >>> 4)];
    uuidChars[17] = HEX_DIGITS[(int)  (mostSignificantBits & 0x000000000000000fL)];
    uuidChars[18] = '-';
    uuidChars[19] = HEX_DIGITS[(int) ((leastSignificantBits & 0xf000000000000000L) >>> 60)];
    uuidChars[20] = HEX_DIGITS[(int) ((leastSignificantBits & 0x0f00000000000000L) >>> 56)];
    uuidChars[21] = HEX_DIGITS[(int) ((leastSignificantBits & 0x00f0000000000000L) >>> 52)];
    uuidChars[22] = HEX_DIGITS[(int) ((leastSignificantBits & 0x000f000000000000L) >>> 48)];
    uuidChars[23] = '-';
    uuidChars[24] = HEX_DIGITS[(int) ((leastSignificantBits & 0x0000f00000000000L) >>> 44)];
    uuidChars[25] = HEX_DIGITS[(int) ((leastSignificantBits & 0x00000f0000000000L) >>> 40)];
    uuidChars[26] = HEX_DIGITS[(int) ((leastSignificantBits & 0x000000f000000000L) >>> 36)];
    uuidChars[27] = HEX_DIGITS[(int) ((leastSignificantBits & 0x0000000f00000000L) >>> 32)];
    uuidChars[28] = HEX_DIGITS[(int) ((leastSignificantBits & 0x00000000f0000000L) >>> 28)];
    uuidChars[29] = HEX_DIGITS[(int) ((leastSignificantBits & 0x000000000f000000L) >>> 24)];
    uuidChars[30] = HEX_DIGITS[(int) ((leastSignificantBits & 0x0000000000f00000L) >>> 20)];
    uuidChars[31] = HEX_DIGITS[(int) ((leastSignificantBits & 0x00000000000f0000L) >>> 16)];
    uuidChars[32] = HEX_DIGITS[(int) ((leastSignificantBits & 0x000000000000f000L) >>> 12)];
    uuidChars[33] = HEX_DIGITS[(int) ((leastSignificantBits & 0x0000000000000f00L) >>> 8)];
    uuidChars[34] = HEX_DIGITS[(int) ((leastSignificantBits & 0x00000000000000f0L) >>> 4)];
    uuidChars[35] = HEX_DIGITS[(int)  (leastSignificantBits & 0x000000000000000fL)];

    return new String(uuidChars);
}
 
Example 19
Source File: VideoUtil.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
public static UUID timeUUIDForStream() {
   UUID original = IrisUUID.timeUUID();

   long lsb = original.getLeastSignificantBits() | UUID_MAC_ULBIT;
   return new UUID(original.getMostSignificantBits(), lsb);
}
 
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());
}