Package com.github.f4b6a3.uuid.util
Class UuidConverter
- java.lang.Object
-
- com.github.f4b6a3.uuid.util.UuidConverter
-
public final class UuidConverter extends Object
Utility that converts UUIDs to and from strings, byte arrays or other UUID types.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static UUIDfromBytes(byte[] bytes)Get a UUID from an array of bytes.static UUIDfromString(String string)Get a UUID from a string.static UUIDtoAndFromMsGuid(UUID uuid)Convert a UUID to and from a MS GUID.static byte[]toBytes(UUID uuid)Get the array of bytes from a UUID.static StringtoString(UUID uuid)Get a string from a UUID.static UUIDtoTimeBasedUuid(UUID uuid)Convert a time-ordered UUID to a time-based UUID.static UUIDtoTimeOrderedUuid(UUID uuid)Convert a time-based UUID to a time-ordered UUID.
-
-
-
Method Detail
-
toBytes
public static byte[] toBytes(UUID uuid)
Get the array of bytes from a UUID.- Parameters:
uuid- a UUID- Returns:
- an array of bytes
-
fromBytes
public static UUID fromBytes(byte[] bytes)
Get a UUID from an array of bytes.- Parameters:
bytes- an array of bytes- Returns:
- a UUID
- Throws:
InvalidUuidException- if invalid
-
toString
public static String toString(UUID uuid)
Get a string from a UUID. It's an alternative toUUID.toString().- Parameters:
uuid- a UUID- Returns:
- a UUID string
-
fromString
public static UUID fromString(String string)
Get a UUID from a string. It accepts strings: - With URN prefix: "urn:uuid:"; - With curly braces: '{' and '}'; - With upper or lower case; - With or without hyphens. It's a better alternative toUUID.fromString(String).- Parameters:
string- a UUID string- Returns:
- a UUID
- Throws:
InvalidUuidException- if invalid
-
toTimeBasedUuid
public static UUID toTimeBasedUuid(UUID uuid)
Convert a time-ordered UUID to a time-based UUID.- Parameters:
uuid- a UUID- Returns:
- another UUID
- Throws:
IllegalArgumentException- if the input is not a time-ordered UUID
-
toTimeOrderedUuid
public static UUID toTimeOrderedUuid(UUID uuid)
Convert a time-based UUID to a time-ordered UUID.- Parameters:
uuid- a UUID- Returns:
- another UUID
- Throws:
IllegalArgumentException- if the input is not a time-based UUID
-
toAndFromMsGuid
public static UUID toAndFromMsGuid(UUID uuid)
Convert a UUID to and from a MS GUID. This method is only useful for MS SQL Server. It rearranges the most significant bytes from big-endian to little-endian, and vice-versa. The Microsoft GUID format stores the most significant bytes as little-endian, while the least significant bytes are stored as big-endian (network order).- Parameters:
uuid- a UUID- Returns:
- another UUID
-
-