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:domain.Employee.java

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

From source file:org.linguafranca.pwdb.kdbx.dom.DomHelper.java

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.dom.DomHelper.java

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.linuxbox.enkive.docstore.mongo.FileDocStoreServiceTest.java

private static byte[] generateFakeRandomHash() {
    final byte[] result = new byte[20];
    final UUID u = UUID.randomUUID();

    // transfer bits into array

    long bits = u.getMostSignificantBits();
    for (int i = 0; i < 8; i++) {
        result[i] = (byte) (bits & 0xff);
    }/*w  w w . j av  a 2  s .  co  m*/

    bits = u.getLeastSignificantBits();
    for (int i = 8; i < 16; i++) {
        result[i] = (byte) (bits & 0xff);
    }

    // remaining bytes should be 0s

    return result;
}

From source file:org.openmrs.module.casereport.DocumentUtil.java

/**
 * Converts the specified uuid to its decimal representation
 * //  w w w .  jav  a  2 s.  c om
 * @param uuid the uuid to convert
 * @return a string representation of the decimal number
 */
public static String convertToDecimal(UUID uuid) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(uuid.getMostSignificantBits());
    bb.putLong(uuid.getLeastSignificantBits());
    BigInteger bi = new BigInteger(bb.array());
    //Get the unsigned representation for -ve numbers
    if (bi.compareTo(BigInteger.ZERO) < 0) {
        bi = DECIMAL_REP_COUNT.add(bi);
    }
    return bi.toString();
}

From source file:ec.edu.chyc.manejopersonal.util.ServerUtils.java

/***
 * Devuelve un UUID generado y codificado en Base64
 *
 * @return Uuid codificado en Base64//  w  w  w .  j a va2  s . c om
 */
public static String generateB64Uuid() {
    UUID uuid = UUID.randomUUID();
    ByteBuffer uuidBytes = ByteBuffer.wrap(new byte[16]);
    uuidBytes.putLong(uuid.getMostSignificantBits()).putLong(uuid.getLeastSignificantBits());
    String asB64 = Base64.getEncoder().encodeToString(uuidBytes.array());
    return asB64;
}

From source file:UUIDGenerator.java

private static byte[] createType4() {
    UUID type4 = UUID.randomUUID();
    byte[] uuid = new byte[16];
    longToBytes(type4.getMostSignificantBits(), uuid, 0);
    longToBytes(type4.getLeastSignificantBits(), uuid, 8);
    return uuid;//from   w w  w .ja va 2s.  co m
}

From source file:com.codelanx.codelanxlib.util.auth.UUIDFetcher.java

/**
 * Converts a {@link UUID} into bytes/* ww  w.  ja  v  a2 s .  c o m*/
 * 
 * @since 0.0.1
 * @version 0.0.1
 * 
 * @param uuid The {@link UUID} to convert
 * @return The new byte array
 */
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:Main.java

private static byte[] encodeUrnUuid(String urn, int position, ByteBuffer bb) {
    String uuidString = urn.substring(position, urn.length());
    UUID uuid;
    try {/*  w  w  w .  j  a  v a 2s.  c om*/
        uuid = UUID.fromString(uuidString);
    } catch (IllegalArgumentException e) {
        //Log.w(TAG, "encodeUrnUuid invalid urn:uuid format - " + urn);
        return null;
    }
    // UUIDs are ordered as byte array, which means most significant first
    bb.order(ByteOrder.BIG_ENDIAN);
    bb.putLong(uuid.getMostSignificantBits());
    bb.putLong(uuid.getLeastSignificantBits());
    return byteBufferToArray(bb);
}

From source file:com.palantir.atlasdb.ptobject.EncodingUtils.java

public static byte[] encodeUUID(UUID uuid) {
    return ByteBuffer.allocate(2 * Longs.BYTES).order(ByteOrder.BIG_ENDIAN)
            .putLong(uuid.getMostSignificantBits()).putLong(uuid.getLeastSignificantBits()).array();
}