Package org.leplus.ristretto.util
Class ReproducibleUUIDs
- java.lang.Object
-
- org.leplus.ristretto.util.ReproducibleUUIDs
-
public final class ReproducibleUUIDs extends Object
This class contains utility methods that generate deterministic UUIDs. Meaning that given the same input, these methods will always return the same UUID, as opposed toUUID.randomUUID()
. The produced UUIDs may not be universally unique (since other code using the same method on the same input would have produce the same UUIDs) but it can still be useful in situations where you need exactly that: be able to generate a UUID and now that other parts of a system will be able to generate a matching UUID for the same input.For example if two parts of a system receive a file and need to independently produce pieces of data that will later have to be reconciled. Then each piece of data could have it's own unique UUID plus a reference UUID generated from the file using one of the methods below. Then both parts of the system will have generated the same reference UUID allowing for easier reconciliation.
- Since:
- 1.0.0
- Author:
- Thomas Leplus
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static UUID
fromByteBuffer(ByteBuffer buffer)
Generates a UUID from the given byte buffer.static UUID
fromBytes(byte... bytes)
Generates a UUID from the given bytes.static UUID
fromInputStream(InputStream input)
Generates a UUID from the given input stream.static UUID
fromString(String s)
Generates a UUID from the given String.static UUID
fromUUIDs(UUID... uuids)
Generates a UUID from the given UUIDs.
-
-
-
Method Detail
-
fromString
public static UUID fromString(String s)
Generates a UUID from the given String. The same String will always produce the same UUID.- Parameters:
s
- the input string.- Returns:
- the resulting UUID.
-
fromBytes
public static UUID fromBytes(byte... bytes)
Generates a UUID from the given bytes. The same bytes will always produce the same UUID.- Parameters:
bytes
- the input bytes.- Returns:
- the resulting UUID.
-
fromByteBuffer
public static UUID fromByteBuffer(ByteBuffer buffer)
Generates a UUID from the given byte buffer. The same bytes will always produce the same UUID.- Parameters:
buffer
- the input byte buffer.- Returns:
- the resulting UUID.
-
fromInputStream
public static UUID fromInputStream(InputStream input) throws IOException
Generates a UUID from the given input stream. The same bytes will always produce the same UUID.- Parameters:
input
- the input stream.- Returns:
- the resulting UUID.
- Throws:
IOException
- if an I/O error occurs.
-
-