Package org.passay
Class PassayUtils
java.lang.Object
org.passay.PassayUtils
Provides utility methods for this package.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendRandomCharacters(UnicodeString source, CharBuffer target, int count, Random rand) Appends characters to the supplied target with count random characters from source.static <T> TassertNotNullArg(T o, String msg) ThrowsIllegalArgumentExceptionif the supplied object is null.static <T> TassertNotNullArgOr(T o, Predicate<T> predicate, String msg) ThrowsIllegalArgumentExceptionif the supplied object is null or the supplied predicate returns true.static voidClears the supplied object by writing zeros to its data structure.static intcodePointCount(String string) Returns the number of code points in the supplied string.static byte[]toByteArray(CharSequence text, Charset charset) Converts the supplied text to a byte array using the supplied charset.private static ByteBuffertoByteBuffer(CharSequence text, Charset charset) Converts the supplied text to a byte buffer using the supplied charset.static StringtoString(int... codePoints) Creates a new string from the supplied code points.
-
Constructor Details
-
PassayUtils
private PassayUtils()Default constructor.
-
-
Method Details
-
assertNotNullArg
ThrowsIllegalArgumentExceptionif the supplied object is null.- Type Parameters:
T- type of object- Parameters:
o- to checkmsg- to include in the exception- Returns:
- supplied object
-
assertNotNullArgOr
ThrowsIllegalArgumentExceptionif the supplied object is null or the supplied predicate returns true.- Type Parameters:
T- type of object- Parameters:
o- to checkpredicate- to testmsg- to include in the exception- Returns:
- supplied object
-
codePointCount
Returns the number of code points in the supplied string.- Parameters:
string- to count characters- Returns:
- number of code points
-
toString
Creates a new string from the supplied code points.- Parameters:
codePoints- to create string with- Returns:
- new string
-
toByteArray
Converts the supplied text to a byte array using the supplied charset.- Parameters:
text- to convert to a byte arraycharset- to use for the conversion- Returns:
- encoded byte array
-
toByteBuffer
Converts the supplied text to a byte buffer using the supplied charset.- Parameters:
text- to convert to a byte arraycharset- to use for the conversion- Returns:
- encoded byte buffer
-
clear
Clears the supplied object by writing zeros to its data structure. The following types are supported:- char[]
- byte[]
- int[]
- long[]
- CharBuffer
- ByteBuffer
- IntBuffer
- LongBuffer
- Parameters:
o- to clear- Throws:
IllegalArgumentException- if the supplied object cannot be cleared
-
appendRandomCharacters
public static void appendRandomCharacters(UnicodeString source, CharBuffer target, int count, Random rand) Appends characters to the supplied target with count random characters from source.- Parameters:
source- of random characters.target- character sequence that will hold characters.count- number of random characters.rand- to select characters from source.
-