Returns an instance of uuid. - Android java.util

Android examples for java.util:UUID

Description

Returns an instance of uuid.

Demo Code


//package com.java2s;

import java.util.UUID;

public class Main {
    /**//from   ww  w. j  av a  2 s .  c  om
     * Returns an instance of uuid.
     * 
     * @param uuid byte[16]
     * @return uuid
     */
    public static java.util.UUID toUUID(byte[] uuid) {
        long msb = 0;
        long lsb = 0;
        assert uuid.length == 16;
        for (int i = 0; i < 8; i++) {
            msb = (msb << 8) | (uuid[i] & 0xff);
        }
        for (int i = 8; i < 16; i++) {
            lsb = (lsb << 8) | (uuid[i] & 0xff);
        }
        UUID u = new UUID(msb, lsb);
        return java.util.UUID.fromString(u.toString());
    }
}

Related Tutorials