Refine search
@Override public final java.util.UUID convert(final ByteBuffer o) { return new java.util.UUID(o.getLong(), o.getLong()); } };
private static String decodeUrnUuid(byte[] serviceData, StringBuilder urnBuilder) { ByteBuffer buf = ByteBuffer.wrap(serviceData); buf.order(ByteOrder.BIG_ENDIAN); long mostSignificantBytes, leastSignificantBytes; try { buf.position(3); mostSignificantBytes = buf.getLong(); leastSignificantBytes = buf.getLong(); } catch (BufferUnderflowException e){ return ""; } UUID uuid = new UUID(mostSignificantBytes, leastSignificantBytes); urnBuilder.append(uuid.toString()); return urnBuilder.toString(); }
/** * Constructs {@link UUID} from byte array. * * @param bytes Array of bytes. * @param off Offset in {@code bytes} array. * @return UUID value. */ public static UUID bytesToUuid(byte[] bytes, int off) { ByteBuffer buf = ByteBuffer.wrap(bytes, off, 16); buf.order(ByteOrder.BIG_ENDIAN); long most = buf.getLong(); long least = buf.getLong(); return most != 0 && least != 0 ? new UUID(most, least) : null; }
public class UuidUtils { public static UUID asUuid(byte[] bytes) { ByteBuffer bb = ByteBuffer.wrap(bytes); long firstLong = bb.getLong(); long secondLong = bb.getLong(); return new UUID(firstLong, secondLong); } public static byte[] asBytes(UUID uuid) { ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return bb.array(); } }
/** * Creates UUID from the given GenericFixed object. * * @param fixed the fixed * @return uuid object. */ public static UUID createUuidFromFixed(GenericFixed fixed) { ByteBuffer bb = ByteBuffer.wrap(fixed.bytes()); long first = bb.getLong(); long second = bb.getLong(); return new UUID(first, second); }
import org.apache.commons.codec.binary.Base64; private static String uuidToBase64(String str) { Base64 base64 = new Base64(); 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()); } private static String uuidFromBase64(String str) { Base64 base64 = new Base64(); byte[] bytes = base64.decodeBase64(str); ByteBuffer bb = ByteBuffer.wrap(bytes); UUID uuid = new UUID(bb.getLong(), bb.getLong()); return uuid.toString(); }