2018-09-22 17:33:00 +03:00
|
|
|
public static UUID toUUID(String username){
|
|
|
|
ByteBuffer buffer=ByteBuffer.wrap(Arrays.copyOf(username.getBytes(StandardCharsets.US_ASCII),16));
|
|
|
|
return new UUID(buffer.getLong(),buffer.getLong()); // MOST, LEAST
|
|
|
|
}
|
2018-09-17 10:07:32 +03:00
|
|
|
|
2018-09-22 17:33:00 +03:00
|
|
|
public static String toUsername(UUID uuid){
|
|
|
|
byte[]bytes=ByteBuffer.allocate(16).
|
|
|
|
putLong(uuid.getMostSignificantBits()).
|
|
|
|
putLong(uuid.getLeastSignificantBits()).array();
|
2018-09-17 10:07:32 +03:00
|
|
|
|
2018-09-22 17:33:00 +03:00
|
|
|
// Find username end
|
|
|
|
int length=0;
|
|
|
|
while(length<bytes.length&&bytes[length]!=0){
|
|
|
|
length++;
|
|
|
|
}
|
2018-09-17 10:07:32 +03:00
|
|
|
|
2018-09-22 17:33:00 +03:00
|
|
|
// Decode and verify
|
|
|
|
return VerifyHelper.verifyUsername(new String(bytes,0,length,StandardCharsets.US_ASCII));
|
|
|
|
}
|