org.ldaptive
Class LdapUtils

java.lang.Object
  extended by org.ldaptive.LdapUtils

public final class LdapUtils
extends Object

Provides utility methods for this package.

Version:
$Revision: 3120 $ $Date: 2015-10-01 11:50:02 -0400 (Thu, 01 Oct 2015) $
Author:
Middleware Services

Method Summary
static boolean areEqual(Object o1, Object o2)
          Determines equality of the supplied objects by delegating to their hashCode methods.
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.
static
<T> T[]
concatArrays(T[] first, T[]... rest)
          Concatenates multiple arrays together.
static InputStream getResource(String path)
          Parses the supplied path and returns an input stream based on the prefix in the path.
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 byte[] readInputStream(InputStream is)
          Reads the data in the supplied stream and returns it as a byte array.
static byte[] readURL(URL url)
          Reads the data at the supplied URL and returns it as a byte array.
static String utf8Encode(byte[] value)
          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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 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

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

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

readURL

public static byte[] readURL(URL url)
                      throws IOException
Reads the data at the supplied URL and returns it as a byte array.

Parameters:
url - to read
Returns:
bytes read from the URL
Throws:
IOException - if an error occurs reading data

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 by delegating to their hashCode methods.

Parameters:
o1 - to test equality of
o2 - 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 number
objects - to calculate hashCode for
Returns:
hash code for the supplied objects

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

getResource

public static InputStream getResource(String path)
                               throws IOException
Parses the supplied path and returns an input stream based on the prefix in the path. If a path is prefixed with the string "classpath:" it is interpreted as a classpath specification. If a path is prefixed with the string "file:" it is interpreted as a file path.

Parameters:
path - that designates a resource
Returns:
input stream to read the resource
Throws:
IOException - if the resource cannot be read
IllegalArgumentException - if path is not prefixed with either 'classpath:' or 'file:'


Copyright © 2003-2015 Virginia Tech. All Rights Reserved.