Example usage for java.util UUID getLeastSignificantBits

List of usage examples for java.util UUID getLeastSignificantBits

Introduction

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

Prototype

public long getLeastSignificantBits() 

Source Link

Document

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

Usage

From source file:Main.java

/**
 * Generates a Base64 version of UUID//from w w w  .jav a2s.  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[] uuidToBytes(String uuidStr) {
    UUID uuid = stringToUuid(uuidStr);

    ByteBuffer bb = ByteBuffer.allocate(16);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    bb.putLong(uuid.getLeastSignificantBits());
    bb.putLong(uuid.getMostSignificantBits());
    return 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: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: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());
}

From source file:com.github.seqware.queryengine.system.Utility.java

/**
 * Parse a timestamp-less SGID from a String representation
 *
 * @param stringSGID a {@link java.lang.String} object.
 * @return a {@link com.github.seqware.queryengine.util.SGID} object.
 */// w ww .  j  a v  a2  s  . c  om
public static SGID parseSGID(String stringSGID) {
    SGID sgid;
    try {
        UUID uuid = UUID.fromString(stringSGID);
        sgid = new SGID(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits(), 0, null);
    } catch (IllegalArgumentException e) {
        String fRowKey = stringSGID;
        sgid = new SGID(0, 0, 0, fRowKey);
    }
    return sgid;
}

From source file:com.pinterest.deployservice.common.CommonUtils.java

/**
 * TODO figure out how to use guava to achive this
 *
 * @return base64 encoded shorten UUID, e.g. 11YozyYYTvKmuUXpRDvoJA
 *///from   ww w .jav  a2 s . c o m
public static String getBase64UUID() {
    UUID uuid = UUID.randomUUID();
    ByteBuffer buffer = ByteBuffer.wrap(new byte[16]);
    buffer.putLong(uuid.getMostSignificantBits());
    buffer.putLong(uuid.getLeastSignificantBits());
    String base64 = BaseEncoding.base64Url().omitPadding().encode(buffer.array());
    if (base64.charAt(0) == '_') {
        return 'x' + base64.substring(1);
    }
    if (base64.charAt(0) == '-') {
        return 'X' + base64.substring(1);
    }
    return base64;
}

From source file:com.nestedbird.util.UUIDConverter.java

/**
 * Turns a UUID in string format to a Base64 encoded version
 *
 * @param uuidString String representation of the uuid
 * @return base64 encoded version of the uuid
 * @throws IllegalArgumentException String must be a valid uuid
 * @throws NullPointerException     String cannot be null
 *//*w w  w  . j a  v  a  2s.com*/
public static String toBase64(final String uuidString) {
    if (uuidString == null)
        throw new NullPointerException("String cannot be null");
    if (!isUUID(uuidString))
        throw new IllegalArgumentException("string must be a valid uuid");

    final UUID uuid = UUID.fromString(uuidString);
    final ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(uuid.getMostSignificantBits());
    bb.putLong(uuid.getLeastSignificantBits());
    return Base64.encodeBase64URLSafeString(bb.array());
}