/** * Retrieves the time as long based on the byte[] representation of a UUID. * * @param uuid byte[] uuid representation * @return a long representing the time */ public static long getTimeFromUUID(byte[] uuid) { return getTimeFromUUID(TimeUUIDUtils.toUUID(uuid)); }
public static UUID decode(String encoded) { // TODO use with Guava 14 (Jclouds 1.6) // byte[] ba = BaseEncoding.base64Url().decode(encoded); // return TimeUUIDUtils.toUUID(ba); return TimeUUIDUtils.toUUID(DatatypeConverter.parseBase64Binary(encoded + "==")); } }
@Test public void testTimeUUIDAsByteArray() { // Generate UUID, convert to array and back to UUID. Then assert. UUID uuid = TimeUUIDUtils.getUniqueTimeUUIDinMillis(); UUID uuidAfterConversion = TimeUUIDUtils.toUUID(TimeUUIDUtils.asByteArray(uuid)); assertEquals(uuid, uuidAfterConversion); // Used the previously generated UUID, convert to array and back to UUID. Then compare their times. long timeInUUID = TimeUUIDUtils.getTimeFromUUID(TimeUUIDUtils.asByteArray(uuid)); assertEquals((uuid.timestamp() - 0x01b21dd213814000L) / 10000, timeInUUID); }
/** * Retrieves the time as long based on the byte[] representation of a UUID. * * @param uuid byte[] uuid representation * @return a long representing the time */ public static long getTimeFromUUID(byte[] uuid) { return getTimeFromUUID(TimeUUIDUtils.toUUID(uuid)); }
/** * Retrieves the time as long based on the byte[] representation of a UUID. * * @param uuid byte[] uuid representation * @return a long representing the time */ public static long getTimeFromUUID(byte[] uuid) { return getTimeFromUUID(TimeUUIDUtils.toUUID(uuid)); }