UUID utils
This commit is contained in:
21
core/src/main/java/mc/core/utils/UuidUtils.java
Normal file
21
core/src/main/java/mc/core/utils/UuidUtils.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package mc.core.utils;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class UuidUtils {
|
||||||
|
|
||||||
|
public static UUID asUuid(byte[] bytes) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(bytes);
|
||||||
|
long firstLong = bb.getLong();
|
||||||
|
long secondLong = bb.getLong();
|
||||||
|
return new UUID(firstLong, secondLong);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] asBytes(UUID uuid) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
|
||||||
|
bb.putLong(uuid.getMostSignificantBits());
|
||||||
|
bb.putLong(uuid.getLeastSignificantBits());
|
||||||
|
return bb.array();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user