Package org.ldaptive
Class LdapUtils
- java.lang.Object
-
- org.ldaptive.LdapUtils
-
public final class LdapUtils extends Object
Provides utility methods for this package.
-
-
Field Summary
Fields Modifier and Type Field Description private static Pattern
CNTRL_PATTERN
Pattern that matches control characters.private static int
HASH_CODE_PRIME
Prime number to assist in calculating hash codes.private static Pattern
IPV4_PATTERN
Pattern to match ipv4 addresses.private static Pattern
IPV6_HEX_COMPRESSED_PATTERN
Pattern to match ipv6 hex compressed addresses.private static Pattern
IPV6_STD_PATTERN
Pattern to match ipv6 addresses.private static int
READ_BUFFER_SIZE
Size of buffer in bytes to use when reading files.
-
Constructor Summary
Constructors Modifier Constructor Description private
LdapUtils()
Default constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
areEqual(Object o1, Object o2)
Determines equality of the supplied objects.static byte[]
base64Decode(String value)
This will decode the supplied value as a base64 encoded string to a byte[].static String
base64Encode(byte... value)
This will convert the supplied value to a base64 encoded string.static String
base64Encode(String value)
This will convert the supplied value to a base64 encoded string.static int
computeHashCode(int seed, Object... objects)
Computes a hash code for the supplied objects using the supplied seed.private static int
computeHashCode(Object object)
Computes a hash code for the supplied object.static <T> T[]
concatArrays(T[] first, T[]... rest)
Concatenates multiple arrays together.static Constructor<?>
createConstructorFromProperty(String property)
Looks for the supplied system property value and loads a class with that name.static byte[]
hexDecode(char[] value)
This will decode the supplied value as a hex encoded string to a byte[].static char[]
hexEncode(byte... value)
This will convert the supplied value to a hex encoded string.static char[]
hexEncode(char... value)
This will convert the supplied value to a hex encoded string.static boolean
isIPAddress(String s)
Returns whether the supplied string represents an IP address.static String
percentDecode(String value)
Implementation of percent decoding as described in RFC 3986 section 2.1.static String
percentEncode(String value)
Implementation of percent encoding as described in RFC 3986 section 2.1.static String
percentEncodeControlChars(String value)
Converts all characters <= 0x1F and 0x7F to percent encoded hex.static byte[]
readInputStream(InputStream is)
Reads the data in the supplied stream and returns it as a byte array.static boolean
shouldBase64Encode(byte[] value)
Determines whether the supplied value should be base64 encoded.static boolean
shouldBase64Encode(String value)
static String
utf8Encode(byte[] value)
This will convert the supplied value to a UTF-8 encoded string.static String
utf8Encode(byte[] value, boolean allowNull)
This will convert the supplied value to a UTF-8 encoded string.static byte[]
utf8Encode(String value)
This will convert the supplied value to a UTF-8 encoded byte array.static byte[]
utf8Encode(String value, boolean allowNull)
This will convert the supplied value to a UTF-8 encoded byte array.
-
-
-
Field Detail
-
READ_BUFFER_SIZE
private static final int READ_BUFFER_SIZE
Size of buffer in bytes to use when reading files.- See Also:
- Constant Field Values
-
HASH_CODE_PRIME
private static final int HASH_CODE_PRIME
Prime number to assist in calculating hash codes.- See Also:
- Constant Field Values
-
IPV4_PATTERN
private static final Pattern IPV4_PATTERN
Pattern to match ipv4 addresses.
-
IPV6_STD_PATTERN
private static final Pattern IPV6_STD_PATTERN
Pattern to match ipv6 addresses.
-
IPV6_HEX_COMPRESSED_PATTERN
private static final Pattern IPV6_HEX_COMPRESSED_PATTERN
Pattern to match ipv6 hex compressed addresses.
-
CNTRL_PATTERN
private static final Pattern CNTRL_PATTERN
Pattern that matches control characters.
-
-
Method Detail
-
base64Encode
public static String base64Encode(byte... value)
This will convert the supplied value to a base64 encoded string. Returns null if the supplied byte array is null.- Parameters:
value
- to base64 encode- Returns:
- base64 encoded value
-
base64Encode
public static String base64Encode(String value)
This will convert the supplied value to a base64 encoded string. Returns null if the supplied string is null.- Parameters:
value
- to base64 encode- Returns:
- base64 encoded value
-
utf8Encode
public static String utf8Encode(byte[] value)
This will convert the supplied value to a UTF-8 encoded string. Returns null if the supplied byte array is null.- Parameters:
value
- to UTF-8 encode- Returns:
- UTF-8 encoded value
-
utf8Encode
public static String utf8Encode(byte[] value, boolean allowNull)
This will convert the supplied value to a UTF-8 encoded string.- Parameters:
value
- to UTF-8 encodeallowNull
- whether to throwNullPointerException
if value is null- Returns:
- UTF-8 encoded value
- Throws:
NullPointerException
- if allowNull is false and value is null
-
utf8Encode
public static byte[] utf8Encode(String value)
This will convert the supplied value to a UTF-8 encoded byte array. Returns null if the supplied string is null.- Parameters:
value
- to UTF-8 encode- Returns:
- UTF-8 encoded value
-
utf8Encode
public static byte[] utf8Encode(String value, boolean allowNull)
This will convert the supplied value to a UTF-8 encoded byte array.- Parameters:
value
- to UTF-8 encodeallowNull
- whether to throwNullPointerException
if value is null- Returns:
- UTF-8 encoded value
- Throws:
NullPointerException
- if allowNull is false and value is null
-
hexEncode
public static char[] hexEncode(byte... value)
This will convert the supplied value to a hex encoded string. Returns null if the supplied byte array is null.- Parameters:
value
- to hex encode- Returns:
- hex encoded value
-
hexEncode
public static char[] hexEncode(char... value)
This will convert the supplied value to a hex encoded string. Returns null if the supplied char array is null.- Parameters:
value
- to hex encode- Returns:
- hex encoded value
-
percentEncode
public static String percentEncode(String value)
Implementation of percent encoding as described in RFC 3986 section 2.1.- Parameters:
value
- to encode- Returns:
- percent encoded value
-
percentEncodeControlChars
public static String percentEncodeControlChars(String value)
Converts all characters <= 0x1F and 0x7F to percent encoded hex.- Parameters:
value
- to encode control characters in- Returns:
- string with percent encoded hex characters
-
base64Decode
public static byte[] base64Decode(String value)
This will decode the supplied value as a base64 encoded string to a byte[]. Returns null if the supplied string is null.- Parameters:
value
- to base64 decode- Returns:
- base64 decoded value
-
hexDecode
public static byte[] hexDecode(char[] value)
This will decode the supplied value as a hex encoded string to a byte[]. Returns null if the supplied character array is null.- Parameters:
value
- to hex decode- Returns:
- hex decoded value
-
percentDecode
public static String percentDecode(String value)
Implementation of percent decoding as described in RFC 3986 section 2.1.- Parameters:
value
- to decode- Returns:
- percent decoded value
-
shouldBase64Encode
public static boolean shouldBase64Encode(String value)
- Parameters:
value
- to inspect- Returns:
- whether the value should be base64 encoded
-
shouldBase64Encode
public static boolean shouldBase64Encode(byte[] value)
Determines whether the supplied value should be base64 encoded. See http://www.faqs.org/rfcs/rfc2849.html for more details.- Parameters:
value
- to inspect- Returns:
- whether the value should be base64 encoded
-
readInputStream
public static byte[] readInputStream(InputStream is) throws IOException
Reads the data in the supplied stream and returns it as a byte array.- Parameters:
is
- stream to read- Returns:
- bytes read from the stream
- Throws:
IOException
- if an error occurs reading data
-
concatArrays
public static <T> T[] concatArrays(T[] first, T[]... rest)
Concatenates multiple arrays together.- Type Parameters:
T
- type of array- Parameters:
first
- array to concatenate. Cannot be null.rest
- of the arrays to concatenate. May be null.- Returns:
- array containing the concatenation of all parameters
-
areEqual
public static boolean areEqual(Object o1, Object o2)
Determines equality of the supplied objects. Array types are automatically detected.- Parameters:
o1
- to test equality ofo2
- to test equality of- Returns:
- whether o1 equals o2
-
computeHashCode
public static int computeHashCode(int seed, Object... objects)
Computes a hash code for the supplied objects using the supplied seed. If a Collection type is found it is iterated over.- Parameters:
seed
- odd/prime numberobjects
- to calculate hashCode for- Returns:
- hash code for the supplied objects
-
computeHashCode
private static int computeHashCode(Object object)
Computes a hash code for the supplied object. Checks for arrays of primitives and Objects then delegates to theArrays
class. OtherwiseObject.hashCode()
is invoked.- Parameters:
object
- to calculate hash code for- Returns:
- hash code
-
isIPAddress
public static boolean isIPAddress(String s)
Returns whether the supplied string represents an IP address. Matches both IPv4 and IPv6 addresses.- Parameters:
s
- to match- Returns:
- whether the supplied string represents an IP address
-
createConstructorFromProperty
public static Constructor<?> createConstructorFromProperty(String property)
Looks for the supplied system property value and loads a class with that name. The default constructor for that class is then returned.- Parameters:
property
- whose value is a class- Returns:
- class constructor or null if no system property was found
- Throws:
IllegalArgumentException
- if an error occurs instantiating the constructor
-
-