/** * Coverts a java.util.UUID into a ByteBuffer. * @param uuid a java.util.UUID * @return a ByteBuffer representaion of the param UUID */ public static ByteBuffer asByteBuffer(java.util.UUID uuid) { if (uuid == null) { return null; } return ByteBuffer.wrap(asByteArray(uuid)); }
final long actual1 = TimeUUIDUtils.getTimeFromUUID(TimeUUIDUtils.asByteArray(u1)); log.info("Java UUID to bytes to time: " + actual1); log.info("Java UUID to bytes time to Date: " + new Date(actual1));
@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); }
/** * Coverts a java.util.UUID into a ByteBuffer. * @param uuid a java.util.UUID * @return a ByteBuffer representaion of the param UUID */ public static ByteBuffer asByteBuffer(java.util.UUID uuid) { if (uuid == null) { return null; } return ByteBuffer.wrap(asByteArray(uuid)); }
/** * Coverts a java.util.UUID into a ByteBuffer. * @param uuid a java.util.UUID * @return a ByteBuffer representaion of the param UUID */ public static ByteBuffer asByteBuffer(java.util.UUID uuid) { if (uuid == null) { return null; } return ByteBuffer.wrap(asByteArray(uuid)); }
public static String encode(UUID uuid) { String base64 = DatatypeConverter.printBase64Binary(TimeUUIDUtils.asByteArray(uuid)); // remove padding if (base64.endsWith("==")) { base64 = base64.substring(0, base64.length() - 2); } return base64; // TODO use with Guava 14 (Jclouds 1.6) // return BaseEncoding.base64Url().omitPadding() // .encode(TimeUUIDUtils.asByteArray(uuid)); }