public class RandomService extends java.lang.Object implements AppContextService<RandomService>
AppContextService
to generate random tokens and passwords.
These need to be secure as they are likely to be used as authentication tokens.Constructor and Description |
---|
RandomService() |
Modifier and Type | Method and Description |
---|---|
void |
cleanup()
AppContext is being closed. |
java.lang.Class |
getType()
Returns the type of service the class should be registered under.
|
byte[] |
randomBytes(int length) |
protected int |
randomInt(int total_chars) |
java.lang.String |
randomString(char[][] chars,
int length)
Generates random sequences of characters taken from the input range,
which has the format:
|
java.lang.String |
randomString(int length)
Generates random sequences of characters in the ranges 'a'..'z', 'A'..'Z'
and '0'..'9'.
|
public void cleanup()
AppContextCleanup
AppContext
is being closed.
Only use this for cleanup that can't be handled by
normal garbage collection or for state which is never returned by reference.cleanup
in interface AppContextCleanup
public java.lang.Class getType()
AppContextService
getType
in interface AppContextService<RandomService>
public java.lang.String randomString(char[][] chars, int length)
{ ( {<first_char>, <second_char>}, ) | {<single_char>}, ) * }The
second_char
value must be higher than the
first_char
value or the output will be undefined or
generate an Exception
.chars
- An array containing ranges of characters and/or single
characterslength
- The length of the desired random stringprotected int randomInt(int total_chars)
total_chars
- public java.lang.String randomString(int length)
length
- The desired length of the output Stringpublic byte[] randomBytes(int length)