Package com.github.f4b6a3.uuid.util
Class MachineId
- java.lang.Object
-
- com.github.f4b6a3.uuid.util.MachineId
-
public final class MachineId extends Object
Utility class to generate machine ID. It works in three steps: 1. Create a string containing host name, MAC and IP; 2. Create a hash of the string using SHA-256 algorithm; 3. Create the identifier using part of the resulting hash. If the host name, MAC or IP changes, the identifier will also change.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]getMachineHash()Returns the machine hash in a byte array.static StringgetMachineHexa()Returns the machine hash in hexadecimal format.static longgetMachineId()Returns a number generated from the machine hash.static StringgetMachineString()Returns a string containing host name, MAC and IP.static UUIDgetMachineUuid()Returns a UUID generated from the machine hash.
-
-
-
Method Detail
-
getMachineId
public static long getMachineId()
Returns a number generated from the machine hash. It uses the first 8 bytes of the machine hash.- Returns:
- a number
-
getMachineUuid
public static UUID getMachineUuid()
Returns a UUID generated from the machine hash. It uses the first 16 bytes of the machine hash. The UUID version is 4.- Returns:
- a UUID
-
getMachineHexa
public static String getMachineHexa()
Returns the machine hash in hexadecimal format. The returning string has 64 chars.- Returns:
- a string
-
getMachineHash
public static byte[] getMachineHash()
Returns the machine hash in a byte array.- Returns:
- a byte array
-
getMachineString
public static String getMachineString()
Returns a string containing host name, MAC and IP. Output format: "hostname123 11-22-33-44-55-66 123.123.123.123" Note: a network interface may have more than one IP address.- Returns:
- a string
-
-