Converting between java.util.UUID and byte[]

Using java-uuid-generator

UUIDs?

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
@cowtowncoder

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