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