public final class UuidFactory extends Object
Uuid
instances.
Included are methods to create a Uuid
with a given 128-bit value or a string
representation of such a value, to generate new Uuid
values, and to read a binary
representation of a Uuid
from a stream.
Modifier and Type | Method and Description |
---|---|
static Uuid |
create(long bits0,
long bits1)
Creates a new
Uuid with the specified 128-bit value. |
static Uuid |
create(String s)
Creates a new
Uuid with the 128-bit value represented by the specified string. |
static Uuid |
generate()
Generates a new
Uuid with 122 bits of its value produced from a
cryptographically strong random sequence. |
static Uuid |
read(InputStream in)
Creates a new
Uuid with the 128-bit value obtained by unmarshalling a binary
representation from the supplied InputStream . |
public static Uuid create(long bits0, long bits1)
Uuid
with the specified 128-bit value.
This method can be used to create a Uuid
with a value that has been
previously generated, perhaps by an external mechanism.
bits0
- the most significant 64 bits of the 128-bit valuebits1
- the least significant 64 bits of the 128-bit valueUuid
with the given valuepublic static Uuid create(String s)
Uuid
with the 128-bit value represented by the specified string.
The supplied string representation must be in the format defined by Uuid.toString
except that uppercase hexadecimal digits are allowed.
s
- the string representation to create the Uuid
withUuid
with the value represented by the given stringIllegalArgumentException
- if the supplied string representation does not conform to
the specified formatNullPointerException
- if s
is null
public static Uuid generate()
Uuid
with 122 bits of its value produced from a
cryptographically strong random sequence.
The value of a Uuid
returned by this method is computationally difficult to
guess and is highly likely to be unique with respect to all other Uuid
values
returned by this method over space and time.
Specifically, this method creates a new Uuid
with the a variant
field of 0x2
, a version
field of 0x4
, and the
remaining 122 bits of its value produced from a cryptographically strong random sequence.
Uuid
SecureRandom
public static Uuid read(InputStream in) throws IOException
Uuid
with the 128-bit value obtained by unmarshalling a binary
representation from the supplied InputStream
.
Specifically, this method reads 16 bytes from the stream, and then it creates a new
Uuid
with the 128-bit value represented by those bytes interpreted in network
(big-endian) byte order.
in
- the InputStream
to read the Uuid
fromUuid
with the value unmarshalled from the streamIOException
- if an I/O exception occurs while performing this operationNullPointerException
- if in
is null
Copyright © GigaSpaces.