whitespace fixups
[jSite2.git] / src / net / pterodactylus / jsite / util / IdGenerator.java
index 4bcb093..083f8d5 100644 (file)
@@ -23,21 +23,37 @@ import java.util.Random;
 
 /**
  * A generator for internal IDs.
- * 
+ *
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
  */
 public class IdGenerator {
 
+       /** The default length of IDs (in bytes before conversion to a string). */
+       public static final int DEFAULT_LENGTH = 20;
+
        /** The RNG used to created IDs. */
        private static Random random = new Random();
 
        /**
-        * Generates a new random ID, consisting of 16 random bytes.
-        * 
+        * Generates a new random ID, consisting of {@link #DEFAULT_LENGTH} random
+        * bytes.
+        *
         * @return The new ID
         */
        public static byte[] generateId() {
-               byte[] idBytes = new byte[16];
+               return generateId(DEFAULT_LENGTH);
+       }
+
+       /**
+        * Generates a new random ID, consisting of <code>length</code> random
+        * bytes.
+        *
+        * @param length
+        *            The length of the ID in bytes before conversion to a string
+        * @return The new ID
+        */
+       public static byte[] generateId(int length) {
+               byte[] idBytes = new byte[length];
                random.nextBytes(idBytes);
                return idBytes;
        }