Io sono la conversione UUID di byte utilizzando questo codiceconvertito uuid al byte, che funziona quando si utilizza UUID.nameUUIDFromBytes (b)
public byte[] getIdAsByte(UUID uuid)
{
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
return bb.array();
}
Tuttavia, se provo a ricreare l'UUID di utilizzare questa funzione,
public UUID frombyte(byte[] b)
{
return UUID.nameUUIDFromBytes(b);
}
Non è lo stesso UUID. La conversione casuale di unUUIDO indietro e indietro ne restituisce due diversi.
UUID u = UUID.randomUUID();
System.out.println(u.toString());
System.out.println(frombyte(getIdAsByte(u)).toString());
stampe:
1ae004cf-0f48-469f-8a94-01339afaec41
8b5d1a71-a4a0-3b46-bec3-13ab9ab12e8e
correlati, Eventuali duplicati: [? Cosa namespace fa l'uso JDK per generare un UUID con nameUUIDFromBytes] (http://stackoverflow.com/questions/9504519/what-namespace-does -the-jdk-usa-per-generare-un-uuid-con-nomeuuidfrombytes) –