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:com.networknt.light.util.HashUtil.java

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

From source file:com.cnaude.mutemanager.UUIDFetcher.java

public static byte[] toBytes(UUID uuid) {
    ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
    byteBuffer.putLong(uuid.getMostSignificantBits());
    byteBuffer.putLong(uuid.getLeastSignificantBits());
    return byteBuffer.array();
}

From source file:org.brekka.phalanx.core.services.impl.AbstractCryptoService.java

/**
 * From http://stackoverflow.com/questions/772802/storing-uuid-as-base64-string.
 * @param uuid/*w  w  w .j  a  va 2 s.c  om*/
 * @return
 */
public static byte[] toBytes(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));
    }
    for (int i = 8; i < 16; i++) {
        buffer[i] = (byte) (lsb >>> 8 * (7 - i));
    }
    return buffer;
}

From source file:com.intellectualcrafters.plot.uuid.UUIDFetcher.java

@SuppressWarnings("unused")
public static byte[] toBytes(final UUID uuid) {
    final ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
    byteBuffer.putLong(uuid.getMostSignificantBits());
    byteBuffer.putLong(uuid.getLeastSignificantBits());
    return byteBuffer.array();
}

From source file:org.linguafranca.pwdb.kdbx.Helpers.java

public static String base64FromUuid(UUID uuid) {
    byte[] buffer = new byte[16];
    ByteBuffer b = ByteBuffer.wrap(buffer);
    b.putLong(uuid.getMostSignificantBits());
    b.putLong(8, uuid.getLeastSignificantBits());
    // round the houses for Android
    return new String(Base64.encodeBase64(buffer));
}

From source file:org.linguafranca.pwdb.kdbx.Helpers.java

public static String hexStringFromUuid(UUID uuid) {
    byte[] buffer = new byte[16];
    ByteBuffer b = ByteBuffer.wrap(buffer);
    b.putLong(uuid.getMostSignificantBits());
    b.putLong(8, uuid.getLeastSignificantBits());
    // round the houses for Android
    return new String(Hex.encodeHex(buffer));
}

From source file:com.enonic.cms.framework.util.UUIDGenerator.java

/**
 * Generate random uuid.//from   w  w w.  j a v  a2  s.co m
 */
public static String randomUUID() {
    UUID uuid = UUID.randomUUID();

    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DataOutputStream dataOut = new DataOutputStream(out);
        dataOut.writeLong(uuid.getMostSignificantBits());
        dataOut.writeLong(uuid.getLeastSignificantBits());
        dataOut.close();
        return new String(Hex.encodeHex(out.toByteArray()));
    } catch (Exception e) {
        return uuid.toString();
    }
}

From source file:net.geertvos.theater.core.util.UUIDGen.java

/** decomposes a uuid into raw bytes. */
public static byte[] decompose(UUID uuid) {
    long most = uuid.getMostSignificantBits();
    long least = uuid.getLeastSignificantBits();
    byte[] b = new byte[16];
    for (int i = 0; i < 8; i++) {
        b[i] = (byte) (most >>> ((7 - i) * 8));
        b[8 + i] = (byte) (least >>> ((7 - i) * 8));
    }// ww w  . j  a  v a 2s.c o m
    return b;
}

From source file:com.networknt.utility.Util.java

/**
 * Generate UUID across the entire app and it is used for correlationId.
 *
 * @return String correlationId//from ww  w .j  a  v a2s  .  co  m
 */
public static String getUUID() {
    UUID id = UUID.randomUUID();
    ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(id.getMostSignificantBits());
    bb.putLong(id.getLeastSignificantBits());
    return Base64.encodeBase64URLSafeString(bb.array());
}

From source file:net.geertvos.theater.core.util.UUIDGen.java

/** writes a uuid to an output stream. */
public static void write(UUID uuid, DataOutput dos) throws IOException {
    dos.writeLong(uuid.getMostSignificantBits());
    dos.writeLong(uuid.getLeastSignificantBits());
}