I'm transforming a UUID in a byte array to send it using a socket using the code above:
UUID id = UUID.randomUUID();
String cleanString = id.toString().replaceAll("-", "");
byte[] bytes = cleanString.getBytes();
to get it back on the other side i use:
String fullString = new String(bytes);
fullString = fullString.substring(0, 8) + "-" + fullString.substring(8, 12) + "-" + fullString.substring(12, 16) + "-" + fullString.substring(16, 20) + "-" + fullString.substring(20, 32);
UUID id = UUID.fromString(fullString);
Well, that's works fine except by the fact that it uses 32 bytes (256 bits) insted the 16 bytes (128 bits) that is the real UUID size, and i really need to save bits.
That's clear that the problem is to use toString, but i couldn't fine any way to convert it to a 16 bytes array.
any idea?