From f67958de5a635795d648f7cc748dfdb870eb5dfb Mon Sep 17 00:00:00 2001 From: Forwolk Date: Thu, 26 Jul 2018 15:47:01 +0300 Subject: [PATCH] UUID utils --- .../main/java/mc/core/utils/UuidUtils.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 core/src/main/java/mc/core/utils/UuidUtils.java diff --git a/core/src/main/java/mc/core/utils/UuidUtils.java b/core/src/main/java/mc/core/utils/UuidUtils.java new file mode 100644 index 0000000..dab5299 --- /dev/null +++ b/core/src/main/java/mc/core/utils/UuidUtils.java @@ -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(); + } +}