Class UUIDGenerator


  • public class UUIDGenerator
    extends java.lang.Object
    Simple generation of a UUID.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int BITS_PER_BYTE
      Number of bits per byte.
      static int BYTES_PER_INT
      Number of bytes per integer.
      protected static java.util.Random rand
      Standard random number generator.
      protected static java.security.SecureRandom secrand
      Secure random number generator.
      protected static StringManager sm
      StringManager for internationalized strings.
      static int UUID_LENGTH
      Length of a UUID in bytes.
      static int UUID_VERSION
      UUID version.
    • Constructor Summary

      Constructors 
      Constructor Description
      UUIDGenerator()
      Constructs a new UUIDGenerator.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void nextBytes​(byte[] into, int offset, int length, java.util.Random r)
      Same as java.util.Random.nextBytes except this one we don't have to allocate a new byte array
      static byte[] randomUUID​(boolean secure)
      Generates a random UUID.
      static byte[] randomUUID​(boolean secure, byte[] into, int offset)
      Generates a random UUID and stores it in the provided byte array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • sm

        protected static final StringManager sm
        StringManager for internationalized strings.
      • UUID_LENGTH

        public static final int UUID_LENGTH
        Length of a UUID in bytes.
        See Also:
        Constant Field Values
      • BYTES_PER_INT

        public static final int BYTES_PER_INT
        Number of bytes per integer.
        See Also:
        Constant Field Values
      • BITS_PER_BYTE

        public static final int BITS_PER_BYTE
        Number of bits per byte.
        See Also:
        Constant Field Values
      • secrand

        protected static final java.security.SecureRandom secrand
        Secure random number generator.
      • rand

        protected static final java.util.Random rand
        Standard random number generator.
    • Constructor Detail

      • UUIDGenerator

        public UUIDGenerator()
        Constructs a new UUIDGenerator.
    • Method Detail

      • randomUUID

        public static byte[] randomUUID​(boolean secure)
        Generates a random UUID.
        Parameters:
        secure - Whether to use a secure random generator
        Returns:
        The generated UUID as a byte array
      • randomUUID

        public static byte[] randomUUID​(boolean secure,
                                        byte[] into,
                                        int offset)
        Generates a random UUID and stores it in the provided byte array.
        Parameters:
        secure - Whether to use a secure random generator
        into - The byte array to store the UUID
        offset - The offset in the byte array
        Returns:
        The byte array containing the UUID
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - If the byte array is too small
      • nextBytes

        public static void nextBytes​(byte[] into,
                                     int offset,
                                     int length,
                                     java.util.Random r)
        Same as java.util.Random.nextBytes except this one we don't have to allocate a new byte array
        Parameters:
        into - byte[]
        offset - int
        length - int
        r - Random