Converting between java.util.UUID and byte[]

Using java-uuid-generator


UUID in Java beyond java.util.UUID

UUID uuid = Generators.timeBasedGenerator().generate();

Constructing java.util.UUID from byte[] using JUG

byte[] rawUuidBytes = ...; // byte array with 16 bytes
UUID uuidFromBytes = UUIDUtil.uuid(rawUuidBytes);
// or, if not 0-offset:
UUID uuid2 = UUIDUtil.uuid(rawUuidBytes, offset);

Serializing java.util.UUID as byte[]

byte[] asBytes = UUIDUtil.asByteArray(uuidFromBytes);
// or, if using an existing buffer
byte[] outputBuffer = new byte[1000];
// append at position #100
UUIDUtil.toByteArray(uuid, outputBuffer, 100);

Faster from-String conversion

UUID uuidFromStr = UUIDUtil.uuid("ebb8e8fe-b1b1-11d7-8adb-00b0d078fa18");

Open Source developer, most known for Jackson data processor (nee “JSON library”), author of many, many other OSS libraries for Java, from ClassMate to Woodstox