Example usage for java.util UUID getMostSignificantBits

List of usage examples for java.util UUID getMostSignificantBits

Introduction

In this page you can find the example usage for java.util UUID getMostSignificantBits.

Prototype

public long getMostSignificantBits() 

Source Link

Document

Returns the most significant 64 bits of this UUID's 128 bit value.

Usage

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 .  j av  a2  s .  co  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();
}

From source file:Main.java

/**
 * Generates a Base64 version of UUID/*from  www.  j  a  v  a  2s.co m*/
 * @return a string in Base64 URL-safe format without padding at the end and no wrapping
 */
public static String randomUuidBase64() {
    UUID uuid = UUID.randomUUID();
    ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(uuid.getMostSignificantBits());
    bb.putLong(uuid.getLeastSignificantBits());
    return encodeUrlSafe64(bb.array());
}

From source file:Main.java

public static byte[] randomUUID() {
    long n;//from w w w  .j  a v a2  s .  c o m
    byte[] result;
    UUID uuid;

    result = new byte[16];
    uuid = UUID.randomUUID();

    n = uuid.getMostSignificantBits();

    result[0] = (byte) (n >> 56 & 0xff);
    result[1] = (byte) (n >> 48 & 0xff);
    result[2] = (byte) (n >> 40 & 0xff);
    result[3] = (byte) (n >> 32 & 0xff);
    result[4] = (byte) (n >> 24 & 0xff);
    result[5] = (byte) (n >> 16 & 0xff);
    result[6] = (byte) (n >> 8 & 0xff);
    result[7] = (byte) (n & 0xff);

    n = uuid.getLeastSignificantBits();

    result[8] = (byte) (n >> 56 & 0xff);
    result[9] = (byte) (n >> 48 & 0xff);
    result[10] = (byte) (n >> 40 & 0xff);
    result[11] = (byte) (n >> 32 & 0xff);
    result[12] = (byte) (n >> 24 & 0xff);
    result[13] = (byte) (n >> 16 & 0xff);
    result[14] = (byte) (n >> 8 & 0xff);
    result[15] = (byte) (n & 0xff);

    return result;
}

From source file:com.hengyi.japp.tools.UuidUtils.java

protected 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.hengyi.japp.tools.UuidUtils.java

protected static String base58Uuid(UUID uuid) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(uuid.getMostSignificantBits());
    bb.putLong(uuid.getLeastSignificantBits());
    return Base58.encode(bb.array());
}

From source file:db.PGKeys.java

private static String randomKey2() {
    UUID rand = UUID.randomUUID();
    return Long.toHexString(rand.getMostSignificantBits() + 37 * rand.getLeastSignificantBits());
}

From source file:uk.ac.ucl.cs.cmic.giftcloud.util.OneWayHash.java

private static String toUID(final UUID uuid) {
    final byte[] b17 = new byte[17];
    fill(b17, 1, uuid.getMostSignificantBits());
    fill(b17, 9, uuid.getLeastSignificantBits());
    return new StringBuilder(64).append(UUID_ROOT).append('.').append(new BigInteger(b17)).toString();
}

From source file:com.microsoft.applicationinsights.extensibility.initializer.SequencePropertyInitializer.java

private static String uuidToBase64() {
    Base64 base64 = new Base64();
    UUID uuid = UUID.randomUUID();
    ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(uuid.getMostSignificantBits());
    bb.putLong(uuid.getLeastSignificantBits());
    return base64.encodeBase64URLSafeString(bb.array());
}