BitWorks { public static byte[] convertUUIDToByteArray(final UUID uuid) { final ByteBuffer bb = ByteBuffer.allocate(16); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return bb.array(); }  static byte[] convertUUIDToByteArray(final UUID uuid); static UUID convertByteArrayToUUID(final byte[] bytes); static byte[] convertStringsToByteArray(final String... values);  }
@Test public void convertUUIDToByteArray() { long msb = 10l; long lsb = 20l; UUID uuid = new UUID(msb, lsb); byte[] bytes = BitWorks.convertUUIDToByteArray(uuid); ByteBuffer buffer = ByteBuffer.wrap(bytes); Assert.assertEquals(msb, buffer.getLong()); Assert.assertEquals(lsb, buffer.getLong()); }