com.unboundid.util
Class StaticUtils

java.lang.Object
  extended by com.unboundid.util.StaticUtils

public final class StaticUtils
extends java.lang.Object

This class provides a number of static utility functions.


Field Summary
static java.lang.String EOL
          The end-of-line marker for this platform.
static byte[] EOL_BYTES
          A byte array containing the end-of-line marker for this platform.
static byte[] NO_BYTES
          A pre-allocated byte array containing zero bytes.
static Control[] NO_CONTROLS
          A pre-allocated empty control array.
static java.lang.String[] NO_STRINGS
          A pre-allocated empty string array.
static int TERMINAL_WIDTH_COLUMNS
          The width of the terminal window, in columns.
 
Method Summary
static
<T> boolean
arraysEqualOrderIndependent(T[] a1, T[] a2)
          Indicates whether the provided arrays have the same elements, ignoring the order in which they appear.
static boolean bothNullOrEqual(java.lang.Object o1, java.lang.Object o2)
          Indicates whether both of the provided objects are null or both are logically equal (using the equals method).
static boolean bothNullOrEqualIgnoreCase(java.lang.String s1, java.lang.String s2)
          Indicates whether both of the provided strings are null or both are logically equal ignoring differences in capitalization (using the equalsIgnoreCase method).
static void byteArrayToCode(byte[] array, java.lang.StringBuilder buffer)
          Appends the Java code that may be used to create the provided byte array to the given buffer.
static java.lang.String capitalize(java.lang.String s)
          Capitalizes the provided string.
static java.lang.String capitalize(java.lang.String s, boolean allWords)
          Capitalizes the provided string.
static java.lang.String concatenateStrings(java.util.List<java.lang.String> l)
          Retrieves a single string which is a concatenation of all of the provided strings.
static java.lang.String concatenateStrings(java.lang.String... a)
          Retrieves a single string which is a concatenation of all of the provided strings.
static java.lang.String concatenateStrings(java.lang.String beforeList, java.lang.String beforeElement, java.lang.String betweenElements, java.lang.String afterElement, java.lang.String afterList, java.util.List<java.lang.String> l)
          Retrieves a single string which is a concatenation of all of the provided strings.
static java.lang.String concatenateStrings(java.lang.String beforeList, java.lang.String beforeElement, java.lang.String betweenElements, java.lang.String afterElement, java.lang.String afterList, java.lang.String... a)
          Retrieves a single string which is a concatenation of all of the provided strings.
static java.io.IOException createIOExceptionWithCause(java.lang.String message, java.lang.Throwable cause)
          Creates a new IOException with a cause.
static java.util.Date decodeGeneralizedTime(java.lang.String t)
          Decodes the provided string as a timestamp in generalized time format.
static java.util.UUID decodeUUID(byte[] b)
          Decodes the value of the provided byte array as a Java UUID.
static java.lang.String encodeGeneralizedTime(java.util.Date d)
          Encodes the provided date in generalized time format.
static java.lang.String encodeGeneralizedTime(long timestamp)
          Encodes the provided timestamp in generalized time format.
static byte[] encodeUUID(java.util.UUID uuid)
          Encodes the provided UUID to a byte array containing its 128-bit representation.
static byte[] getBytes(java.lang.String s)
          Retrieves a UTF-8 byte representation of the provided string.
static java.lang.String getExceptionMessage(java.lang.Throwable t)
          Retrieves a string representation of the provided Throwable object suitable for use in a message.
static java.util.Set<java.lang.String> getSensitiveToCodeAttributeBaseNames()
          Retrieves a set containing the base names (in all lowercase characters) of any attributes that should be considered sensitive for the purposes of the toCode methods.
static java.lang.String getStackTrace(java.lang.StackTraceElement[] elements)
          Returns a single-line string representation of the stack trace.
static void getStackTrace(java.lang.StackTraceElement[] elements, java.lang.StringBuilder buffer)
          Appends a single-line string representation of the stack trace to the given buffer.
static java.lang.String getStackTrace(java.lang.Throwable t)
          Retrieves a single-line string representation of the stack trace for the provided Throwable.
static void getStackTrace(java.lang.Throwable t, java.lang.StringBuilder buffer)
          Appends a single-line string representation of the stack trace for the provided Throwable to the given buffer.
static java.lang.String getUnqualifiedClassName(java.lang.Class<?> c)
          Retrieves the unqualified name (i.e., the name without package information) for the provided class.
static void hexEncode(char c, java.lang.StringBuilder buffer)
          Appends a hex-encoded representation of the provided character to the given buffer.
static boolean isASCIIString(byte[] b)
          Indicates whether the contents of the provided byte array represent an ASCII string, which is also known in LDAP terminology as an IA5 string.
static boolean isHex(char c)
          Indicates whether the provided character is a valid hexadecimal digit.
static boolean isNumericOID(java.lang.String s)
          Indicates whether the provided string is a valid numeric OID.
static boolean isPrintable(char c)
          Indicates whether the provided character is a printable ASCII character, as per RFC 4517 section 3.2.
static boolean isPrintableString(byte[] b)
          Indicates whether the contents of the provided byte array represent a printable LDAP string, as per RFC 4517 section 3.2.
static boolean isSensitiveToCodeAttribute(java.lang.String name)
          Indicates whether the provided attribute name should be considered a sensitive attribute for the purposes of toCode methods.
static boolean isWindows()
          Returns true if and only if the current process is running on a Windows-based operating system.
static java.lang.String millisToHumanReadableDuration(long m)
          Converts a duration in seconds to a string with a human-readable duration which may include days, hours, minutes, and seconds, to the extent that they are needed.
static long millisToNanos(long millis)
          Converts the provided number of milliseconds to nanoseconds.
static long nanosToMillis(long nanos)
          Converts the provided number of nanoseconds to milliseconds.
static int numBytesInUTF8CharacterWithFirstByte(byte b)
          Determines the number of bytes in a UTF-8 character that starts with the given byte.
static java.lang.String secondsToHumanReadableDuration(long s)
          Converts a duration in seconds to a string with a human-readable duration which may include days, hours, minutes, and seconds, to the extent that they are needed.
static void setSensitiveToCodeAttributes(java.util.Collection<java.lang.String> names)
          Specifies the names of any attributes that should be considered sensitive for the purposes of the toCode methods.
static void setSensitiveToCodeAttributes(java.lang.String... names)
          Specifies the names of any attributes that should be considered sensitive for the purposes of the toCode methods.
static boolean stringsEqualIgnoreCaseOrderIndependent(java.lang.String[] a1, java.lang.String[] a2)
          Indicates whether the provided string arrays have the same elements, ignoring the order in which they appear and differences in capitalization.
static java.util.List<java.lang.String> stringToLines(java.lang.String s)
          Converts the provided string (which may include line breaks) into a list containing the lines without the line breaks.
static java.util.List<java.lang.String> toArgumentList(java.lang.String s)
          Attempts to parse the contents of the provided string to an argument list (e.g., converts something like "--arg1 arg1value --arg2 --arg3 arg3value" to a list of "--arg1", "arg1value", "--arg2", "--arg3", "arg3value").
static java.lang.String toHex(byte b)
          Retrieves a hexadecimal representation of the provided byte.
static java.lang.String toHex(byte[] b)
          Retrieves a hexadecimal representation of the contents of the provided byte array.
static void toHex(byte[] b, java.lang.StringBuilder buffer)
          Retrieves a hexadecimal representation of the contents of the provided byte array.
static void toHex(byte[] b, java.lang.String delimiter, java.lang.StringBuilder buffer)
          Retrieves a hexadecimal representation of the contents of the provided byte array.
static void toHex(byte b, java.lang.StringBuilder buffer)
          Appends a hexadecimal representation of the provided byte to the given buffer.
static java.lang.String toHexPlusASCII(byte[] array, int indent)
          Retrieves a hex-encoded representation of the contents of the provided array, along with an ASCII representation of its contents next to it.
static void toHexPlusASCII(byte[] array, int indent, java.lang.StringBuilder buffer)
          Appends a hex-encoded representation of the contents of the provided array to the given buffer, along with an ASCII representation of its contents next to it.
static java.lang.String toInitialLowerCase(java.lang.String s)
          Retrieves a version of the provided string with the first character converted to lowercase but all other characters retaining their original capitalization.
static
<T> java.util.List<T>
toList(T[] array)
          Creates a modifiable list with all of the items of the provided array in the same order.
static java.lang.String toLowerCase(java.lang.String s)
          Retrieves an all-lowercase version of the provided string.
static
<T> java.util.List<T>
toNonNullList(T[] array)
          Creates a modifiable list with all of the items of the provided array in the same order.
static java.lang.String toUTF8String(byte[] b)
          Retrieves a string generated from the provided byte array using the UTF-8 encoding.
static java.lang.String toUTF8String(byte[] b, int offset, int length)
          Retrieves a string generated from the specified portion of the provided byte array using the UTF-8 encoding.
static java.lang.String trimLeading(java.lang.String s)
          Trims only leading spaces from the provided string, leaving any trailing spaces intact.
static java.lang.String trimTrailing(java.lang.String s)
          Trims only trailing spaces from the provided string, leaving any leading spaces intact.
static java.util.List<java.lang.String> wrapLine(java.lang.String line, int maxWidth)
          Wraps the contents of the specified line using the given width.
static java.util.List<java.lang.String> wrapLine(java.lang.String line, int maxFirstLineWidth, int maxSubsequentLineWidth)
          Wraps the contents of the specified line using the given width.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_BYTES

public static final byte[] NO_BYTES
A pre-allocated byte array containing zero bytes.


NO_CONTROLS

public static final Control[] NO_CONTROLS
A pre-allocated empty control array.


NO_STRINGS

public static final java.lang.String[] NO_STRINGS
A pre-allocated empty string array.


EOL

public static final java.lang.String EOL
The end-of-line marker for this platform.


EOL_BYTES

public static final byte[] EOL_BYTES
A byte array containing the end-of-line marker for this platform.


TERMINAL_WIDTH_COLUMNS

public static final int TERMINAL_WIDTH_COLUMNS
The width of the terminal window, in columns.

Method Detail

getBytes

public static byte[] getBytes(java.lang.String s)
Retrieves a UTF-8 byte representation of the provided string.

Parameters:
s - The string for which to retrieve the UTF-8 byte representation.
Returns:
The UTF-8 byte representation for the provided string.

isASCIIString

public static boolean isASCIIString(byte[] b)
Indicates whether the contents of the provided byte array represent an ASCII string, which is also known in LDAP terminology as an IA5 string. An ASCII string is one that contains only bytes in which the most significant bit is zero.

Parameters:
b - The byte array for which to make the determination. It must not be null.
Returns:
true if the contents of the provided array represent an ASCII string, or false if not.

isPrintable

public static boolean isPrintable(char c)
Indicates whether the provided character is a printable ASCII character, as per RFC 4517 section 3.2. The only printable characters are:

Parameters:
c - The character for which to make the determination.
Returns:
true if the provided character is a printable ASCII character, or false if not.

isPrintableString

public static boolean isPrintableString(byte[] b)
Indicates whether the contents of the provided byte array represent a printable LDAP string, as per RFC 4517 section 3.2. The only characters allowed in a printable string are: If the provided array contains anything other than the above characters (i.e., if the byte array contains any non-ASCII characters, or any ASCII control characters, or if it contains excluded ASCII characters like the exclamation point, double quote, octothorpe, dollar sign, etc.), then it will not be considered printable.

Parameters:
b - The byte array for which to make the determination. It must not be null.
Returns:
true if the contents of the provided byte array represent a printable LDAP string, or false if not.

toUTF8String

public static java.lang.String toUTF8String(byte[] b)
Retrieves a string generated from the provided byte array using the UTF-8 encoding.

Parameters:
b - The byte array for which to return the associated string.
Returns:
The string generated from the provided byte array using the UTF-8 encoding.

toUTF8String

public static java.lang.String toUTF8String(byte[] b,
                                            int offset,
                                            int length)
Retrieves a string generated from the specified portion of the provided byte array using the UTF-8 encoding.

Parameters:
b - The byte array for which to return the associated string.
offset - The offset in the array at which the value begins.
length - The number of bytes in the value to convert to a string.
Returns:
The string generated from the specified portion of the provided byte array using the UTF-8 encoding.

toInitialLowerCase

public static java.lang.String toInitialLowerCase(java.lang.String s)
Retrieves a version of the provided string with the first character converted to lowercase but all other characters retaining their original capitalization.

Parameters:
s - The string to be processed.
Returns:
A version of the provided string with the first character converted to lowercase but all other characters retaining their original capitalization.

toLowerCase

public static java.lang.String toLowerCase(java.lang.String s)
Retrieves an all-lowercase version of the provided string.

Parameters:
s - The string for which to retrieve the lowercase version.
Returns:
An all-lowercase version of the provided string.

isHex

public static boolean isHex(char c)
Indicates whether the provided character is a valid hexadecimal digit.

Parameters:
c - The character for which to make the determination.
Returns:
true if the provided character does represent a valid hexadecimal digit, or false if not.

toHex

public static java.lang.String toHex(byte b)
Retrieves a hexadecimal representation of the provided byte.

Parameters:
b - The byte to encode as hexadecimal.
Returns:
A string containing the hexadecimal representation of the provided byte.

toHex

public static void toHex(byte b,
                         java.lang.StringBuilder buffer)
Appends a hexadecimal representation of the provided byte to the given buffer.

Parameters:
b - The byte to encode as hexadecimal.
buffer - The buffer to which the hexadecimal representation is to be appended.

toHex

public static java.lang.String toHex(byte[] b)
Retrieves a hexadecimal representation of the contents of the provided byte array. No delimiter character will be inserted between the hexadecimal digits for each byte.

Parameters:
b - The byte array to be represented as a hexadecimal string. It must not be null.
Returns:
A string containing a hexadecimal representation of the contents of the provided byte array.

toHex

public static void toHex(byte[] b,
                         java.lang.StringBuilder buffer)
Retrieves a hexadecimal representation of the contents of the provided byte array. No delimiter character will be inserted between the hexadecimal digits for each byte.

Parameters:
b - The byte array to be represented as a hexadecimal string. It must not be null.
buffer - A buffer to which the hexadecimal representation of the contents of the provided byte array should be appended.

toHex

public static void toHex(byte[] b,
                         java.lang.String delimiter,
                         java.lang.StringBuilder buffer)
Retrieves a hexadecimal representation of the contents of the provided byte array. No delimiter character will be inserted between the hexadecimal digits for each byte.

Parameters:
b - The byte array to be represented as a hexadecimal string. It must not be null.
delimiter - A delimiter to be inserted between bytes. It may be null if no delimiter should be used.
buffer - A buffer to which the hexadecimal representation of the contents of the provided byte array should be appended.

toHexPlusASCII

public static java.lang.String toHexPlusASCII(byte[] array,
                                              int indent)
Retrieves a hex-encoded representation of the contents of the provided array, along with an ASCII representation of its contents next to it. The output will be split across multiple lines, with up to sixteen bytes per line. For each of those sixteen bytes, the two-digit hex representation will be appended followed by a space. Then, the ASCII representation of those sixteen bytes will follow that, with a space used in place of any byte that does not have an ASCII representation.

Parameters:
array - The array whose contents should be processed.
indent - The number of spaces to insert on each line prior to the first hex byte.
Returns:
A hex-encoded representation of the contents of the provided array, along with an ASCII representation of its contents next to it.

toHexPlusASCII

public static void toHexPlusASCII(byte[] array,
                                  int indent,
                                  java.lang.StringBuilder buffer)
Appends a hex-encoded representation of the contents of the provided array to the given buffer, along with an ASCII representation of its contents next to it. The output will be split across multiple lines, with up to sixteen bytes per line. For each of those sixteen bytes, the two-digit hex representation will be appended followed by a space. Then, the ASCII representation of those sixteen bytes will follow that, with a space used in place of any byte that does not have an ASCII representation.

Parameters:
array - The array whose contents should be processed.
indent - The number of spaces to insert on each line prior to the first hex byte.
buffer - The buffer to which the encoded data should be appended.

hexEncode

public static void hexEncode(char c,
                             java.lang.StringBuilder buffer)
Appends a hex-encoded representation of the provided character to the given buffer. Each byte of the hex-encoded representation will be prefixed with a backslash.

Parameters:
c - The character to be encoded.
buffer - The buffer to which the hex-encoded representation should be appended.

byteArrayToCode

public static void byteArrayToCode(byte[] array,
                                   java.lang.StringBuilder buffer)
Appends the Java code that may be used to create the provided byte array to the given buffer.

Parameters:
array - The byte array containing the data to represent. It must not be null.
buffer - The buffer to which the code should be appended.

getStackTrace

public static java.lang.String getStackTrace(java.lang.Throwable t)
Retrieves a single-line string representation of the stack trace for the provided Throwable. It will include the unqualified name of the Throwable class, a list of source files and line numbers (if available) for the stack trace, and will also include the stack trace for the cause (if present).

Parameters:
t - The Throwable for which to retrieve the stack trace.
Returns:
A single-line string representation of the stack trace for the provided Throwable.

getStackTrace

public static void getStackTrace(java.lang.Throwable t,
                                 java.lang.StringBuilder buffer)
Appends a single-line string representation of the stack trace for the provided Throwable to the given buffer. It will include the unqualified name of the Throwable class, a list of source files and line numbers (if available) for the stack trace, and will also include the stack trace for the cause (if present).

Parameters:
t - The Throwable for which to retrieve the stack trace.
buffer - The buffer to which the information should be appended.

getStackTrace

public static java.lang.String getStackTrace(java.lang.StackTraceElement[] elements)
Returns a single-line string representation of the stack trace. It will include a list of source files and line numbers (if available) for the stack trace.

Parameters:
elements - The stack trace.
Returns:
A single-line string representation of the stack trace.

getStackTrace

public static void getStackTrace(java.lang.StackTraceElement[] elements,
                                 java.lang.StringBuilder buffer)
Appends a single-line string representation of the stack trace to the given buffer. It will include a list of source files and line numbers (if available) for the stack trace.

Parameters:
elements - The stack trace.
buffer - The buffer to which the information should be appended.

getExceptionMessage

public static java.lang.String getExceptionMessage(java.lang.Throwable t)
Retrieves a string representation of the provided Throwable object suitable for use in a message. For runtime exceptions and errors, then a full stack trace for the exception will be provided. For exception types defined in the LDAP SDK, then its getExceptionMessage method will be used to get the string representation. For all other types of exceptions, then the standard string representation will be used.

For all types of exceptions, the message will also include the cause if one exists.

Parameters:
t - The Throwable for which to generate the exception message.
Returns:
A string representation of the provided Throwable object suitable for use in a message.

getUnqualifiedClassName

public static java.lang.String getUnqualifiedClassName(java.lang.Class<?> c)
Retrieves the unqualified name (i.e., the name without package information) for the provided class.

Parameters:
c - The class for which to retrieve the unqualified name.
Returns:
The unqualified name for the provided class.

encodeGeneralizedTime

public static java.lang.String encodeGeneralizedTime(long timestamp)
Encodes the provided timestamp in generalized time format.

Parameters:
timestamp - The timestamp to be encoded in generalized time format. It should use the same format as the System.currentTimeMillis() method (i.e., the number of milliseconds since 12:00am UTC on January 1, 1970).
Returns:
The generalized time representation of the provided date.

encodeGeneralizedTime

public static java.lang.String encodeGeneralizedTime(java.util.Date d)
Encodes the provided date in generalized time format.

Parameters:
d - The date to be encoded in generalized time format.
Returns:
The generalized time representation of the provided date.

decodeGeneralizedTime

public static java.util.Date decodeGeneralizedTime(java.lang.String t)
                                            throws java.text.ParseException
Decodes the provided string as a timestamp in generalized time format.

Parameters:
t - The timestamp to be decoded. It must not be null.
Returns:
The Date object decoded from the provided timestamp.
Throws:
java.text.ParseException - If the provided string could not be decoded as a timestamp in generalized time format.

trimLeading

public static java.lang.String trimLeading(java.lang.String s)
Trims only leading spaces from the provided string, leaving any trailing spaces intact.

Parameters:
s - The string to be processed. It must not be null.
Returns:
The original string if no trimming was required, or a new string without leading spaces if the provided string had one or more. It may be an empty string if the provided string was an empty string or contained only spaces.

trimTrailing

public static java.lang.String trimTrailing(java.lang.String s)
Trims only trailing spaces from the provided string, leaving any leading spaces intact.

Parameters:
s - The string to be processed. It must not be null.
Returns:
The original string if no trimming was required, or a new string without trailing spaces if the provided string had one or more. It may be an empty string if the provided string was an empty string or contained only spaces.

wrapLine

public static java.util.List<java.lang.String> wrapLine(java.lang.String line,
                                                        int maxWidth)
Wraps the contents of the specified line using the given width. It will attempt to wrap at spaces to preserve words, but if that is not possible (because a single "word" is longer than the maximum width), then it will wrap in the middle of the word at the specified maximum width.

Parameters:
line - The line to be wrapped. It must not be null.
maxWidth - The maximum width for lines in the resulting list. A value less than or equal to zero will cause no wrapping to be performed.
Returns:
A list of the wrapped lines. It may be empty if the provided line contained only spaces.

wrapLine

public static java.util.List<java.lang.String> wrapLine(java.lang.String line,
                                                        int maxFirstLineWidth,
                                                        int maxSubsequentLineWidth)
Wraps the contents of the specified line using the given width. It will attempt to wrap at spaces to preserve words, but if that is not possible (because a single "word" is longer than the maximum width), then it will wrap in the middle of the word at the specified maximum width.

Parameters:
line - The line to be wrapped. It must not be null.
maxFirstLineWidth - The maximum length for the first line in the resulting list. A value less than or equal to zero will cause no wrapping to be performed.
maxSubsequentLineWidth - The maximum length for all lines except the first line. This must be greater than zero unless maxFirstLineWidth is less than or equal to zero.
Returns:
A list of the wrapped lines. It may be empty if the provided line contained only spaces.

concatenateStrings

public static java.lang.String concatenateStrings(java.lang.String... a)
Retrieves a single string which is a concatenation of all of the provided strings.

Parameters:
a - The array of strings to concatenate. It must not be null.
Returns:
A string containing a concatenation of all of the strings in the provided array.

concatenateStrings

public static java.lang.String concatenateStrings(java.util.List<java.lang.String> l)
Retrieves a single string which is a concatenation of all of the provided strings.

Parameters:
l - The list of strings to concatenate. It must not be null.
Returns:
A string containing a concatenation of all of the strings in the provided list.

concatenateStrings

public static java.lang.String concatenateStrings(java.lang.String beforeList,
                                                  java.lang.String beforeElement,
                                                  java.lang.String betweenElements,
                                                  java.lang.String afterElement,
                                                  java.lang.String afterList,
                                                  java.lang.String... a)
Retrieves a single string which is a concatenation of all of the provided strings.

Parameters:
beforeList - A string that should be placed at the beginning of the list. It may be null or empty if nothing should be placed at the beginning of the list.
beforeElement - A string that should be placed before each element in the list. It may be null or empty if nothing should be placed before each element.
betweenElements - The separator that should be placed between elements in the list. It may be null or empty if no separator should be placed between elements.
afterElement - A string that should be placed after each element in the list. It may be null or empty if nothing should be placed after each element.
afterList - A string that should be placed at the end of the list. It may be null or empty if nothing should be placed at the end of the list.
a - The array of strings to concatenate. It must not be null.
Returns:
A string containing a concatenation of all of the strings in the provided list.

concatenateStrings

public static java.lang.String concatenateStrings(java.lang.String beforeList,
                                                  java.lang.String beforeElement,
                                                  java.lang.String betweenElements,
                                                  java.lang.String afterElement,
                                                  java.lang.String afterList,
                                                  java.util.List<java.lang.String> l)
Retrieves a single string which is a concatenation of all of the provided strings.

Parameters:
beforeList - A string that should be placed at the beginning of the list. It may be null or empty if nothing should be placed at the beginning of the list.
beforeElement - A string that should be placed before each element in the list. It may be null or empty if nothing should be placed before each element.
betweenElements - The separator that should be placed between elements in the list. It may be null or empty if no separator should be placed between elements.
afterElement - A string that should be placed after each element in the list. It may be null or empty if nothing should be placed after each element.
afterList - A string that should be placed at the end of the list. It may be null or empty if nothing should be placed at the end of the list.
l - The list of strings to concatenate. It must not be null.
Returns:
A string containing a concatenation of all of the strings in the provided list.

secondsToHumanReadableDuration

public static java.lang.String secondsToHumanReadableDuration(long s)
Converts a duration in seconds to a string with a human-readable duration which may include days, hours, minutes, and seconds, to the extent that they are needed.

Parameters:
s - The number of seconds to be represented.
Returns:
A string containing a human-readable representation of the provided time.

millisToHumanReadableDuration

public static java.lang.String millisToHumanReadableDuration(long m)
Converts a duration in seconds to a string with a human-readable duration which may include days, hours, minutes, and seconds, to the extent that they are needed.

Parameters:
m - The number of milliseconds to be represented.
Returns:
A string containing a human-readable representation of the provided time.

nanosToMillis

public static long nanosToMillis(long nanos)
Converts the provided number of nanoseconds to milliseconds.

Parameters:
nanos - The number of nanoseconds to convert to milliseconds.
Returns:
The number of milliseconds that most closely corresponds to the specified number of nanoseconds.

millisToNanos

public static long millisToNanos(long millis)
Converts the provided number of milliseconds to nanoseconds.

Parameters:
millis - The number of milliseconds to convert to nanoseconds.
Returns:
The number of nanoseconds that most closely corresponds to the specified number of milliseconds.

isNumericOID

public static boolean isNumericOID(java.lang.String s)
Indicates whether the provided string is a valid numeric OID. A numeric OID must start and end with a digit, must have at least on period, must contain only digits and periods, and must not have two consecutive periods.

Parameters:
s - The string to examine. It must not be null.
Returns:
true if the provided string is a valid numeric OID, or false if not.

capitalize

public static java.lang.String capitalize(java.lang.String s)
Capitalizes the provided string. The first character will be converted to uppercase, and the rest of the string will be left unaltered.

Parameters:
s - The string to be capitalized.
Returns:
A capitalized version of the provided string.

capitalize

public static java.lang.String capitalize(java.lang.String s,
                                          boolean allWords)
Capitalizes the provided string. The first character of the string (or optionally the first character of each word in the string)

Parameters:
s - The string to be capitalized.
allWords - Indicates whether to capitalize all words in the string, or only the first word.
Returns:
A capitalized version of the provided string.

encodeUUID

public static byte[] encodeUUID(java.util.UUID uuid)
Encodes the provided UUID to a byte array containing its 128-bit representation.

Parameters:
uuid - The UUID to be encoded. It must not be null.
Returns:
The byte array containing the 128-bit encoded UUID.

decodeUUID

public static java.util.UUID decodeUUID(byte[] b)
                                 throws java.text.ParseException
Decodes the value of the provided byte array as a Java UUID.

Parameters:
b - The byte array to be decoded as a UUID. It must not be null.
Returns:
The decoded UUID.
Throws:
java.text.ParseException - If the provided byte array cannot be parsed as a UUID.

isWindows

public static boolean isWindows()
Returns true if and only if the current process is running on a Windows-based operating system.

Returns:
true if the current process is running on a Windows-based operating system and false otherwise.

toArgumentList

public static java.util.List<java.lang.String> toArgumentList(java.lang.String s)
                                                       throws java.text.ParseException
Attempts to parse the contents of the provided string to an argument list (e.g., converts something like "--arg1 arg1value --arg2 --arg3 arg3value" to a list of "--arg1", "arg1value", "--arg2", "--arg3", "arg3value").

Parameters:
s - The string to be converted to an argument list.
Returns:
The parsed argument list.
Throws:
java.text.ParseException - If a problem is encountered while attempting to parse the given string to an argument list.

toList

public static <T> java.util.List<T> toList(T[] array)
Creates a modifiable list with all of the items of the provided array in the same order. This method behaves much like Arrays.asList, except that if the provided array is null, then it will return a null list rather than throwing an exception.

Type Parameters:
T - The type of item contained in the provided array.
Parameters:
array - The array of items to include in the list.
Returns:
The list that was created, or null if the provided array was null.

toNonNullList

public static <T> java.util.List<T> toNonNullList(T[] array)
Creates a modifiable list with all of the items of the provided array in the same order. This method behaves much like Arrays.asList, except that if the provided array is null, then it will return an empty list rather than throwing an exception.

Type Parameters:
T - The type of item contained in the provided array.
Parameters:
array - The array of items to include in the list.
Returns:
The list that was created, or an empty list if the provided array was null.

bothNullOrEqual

public static boolean bothNullOrEqual(java.lang.Object o1,
                                      java.lang.Object o2)
Indicates whether both of the provided objects are null or both are logically equal (using the equals method).

Parameters:
o1 - The first object for which to make the determination.
o2 - The second object for which to make the determination.
Returns:
true if both objects are null or both are logically equal, or false if only one of the objects is null or they are not logically equal.

bothNullOrEqualIgnoreCase

public static boolean bothNullOrEqualIgnoreCase(java.lang.String s1,
                                                java.lang.String s2)
Indicates whether both of the provided strings are null or both are logically equal ignoring differences in capitalization (using the equalsIgnoreCase method).

Parameters:
s1 - The first string for which to make the determination.
s2 - The second string for which to make the determination.
Returns:
true if both strings are null or both are logically equal ignoring differences in capitalization, or false if only one of the objects is null or they are not logically equal ignoring capitalization.

stringsEqualIgnoreCaseOrderIndependent

public static boolean stringsEqualIgnoreCaseOrderIndependent(java.lang.String[] a1,
                                                             java.lang.String[] a2)
Indicates whether the provided string arrays have the same elements, ignoring the order in which they appear and differences in capitalization. It is assumed that neither array contains null strings, and that no string appears more than once in each array.

Parameters:
a1 - The first array for which to make the determination.
a2 - The second array for which to make the determination.
Returns:
true if both arrays have the same set of strings, or false if not.

arraysEqualOrderIndependent

public static <T> boolean arraysEqualOrderIndependent(T[] a1,
                                                      T[] a2)
Indicates whether the provided arrays have the same elements, ignoring the order in which they appear. It is assumed that neither array contains null elements, and that no element appears more than once in each array.

Type Parameters:
T - The type of element contained in the arrays.
Parameters:
a1 - The first array for which to make the determination.
a2 - The second array for which to make the determination.
Returns:
true if both arrays have the same set of elements, or false if not.

numBytesInUTF8CharacterWithFirstByte

public static int numBytesInUTF8CharacterWithFirstByte(byte b)
Determines the number of bytes in a UTF-8 character that starts with the given byte.

Parameters:
b - The byte for which to make the determination.
Returns:
The number of bytes in a UTF-8 character that starts with the given byte, or -1 if it does not appear to be a valid first byte for a UTF-8 character.

isSensitiveToCodeAttribute

public static boolean isSensitiveToCodeAttribute(java.lang.String name)
Indicates whether the provided attribute name should be considered a sensitive attribute for the purposes of toCode methods. If an attribute is considered sensitive, then its values will be redacted in the output of the toCode methods.

Parameters:
name - The name for which to make the determination. It may or may not include attribute options. It must not be null.
Returns:
true if the specified attribute is one that should be considered sensitive for the

getSensitiveToCodeAttributeBaseNames

public static java.util.Set<java.lang.String> getSensitiveToCodeAttributeBaseNames()
Retrieves a set containing the base names (in all lowercase characters) of any attributes that should be considered sensitive for the purposes of the toCode methods. By default, only the userPassword and authPassword attributes and their respective OIDs will be included.

Returns:
A set containing the base names (in all lowercase characters) of any attributes that should be considered sensitive for the purposes of the toCode methods.

setSensitiveToCodeAttributes

public static void setSensitiveToCodeAttributes(java.lang.String... names)
Specifies the names of any attributes that should be considered sensitive for the purposes of the toCode methods.

Parameters:
names - The names of any attributes that should be considered sensitive for the purposes of the toCode methods. It may be null or empty if no attributes should be considered sensitive.

setSensitiveToCodeAttributes

public static void setSensitiveToCodeAttributes(java.util.Collection<java.lang.String> names)
Specifies the names of any attributes that should be considered sensitive for the purposes of the toCode methods.

Parameters:
names - The names of any attributes that should be considered sensitive for the purposes of the toCode methods. It may be null or empty if no attributes should be considered sensitive.

createIOExceptionWithCause

public static java.io.IOException createIOExceptionWithCause(java.lang.String message,
                                                             java.lang.Throwable cause)
Creates a new IOException with a cause. The constructor needed to do this wasn't available until Java SE 6, so reflection is used to invoke this constructor in versions of Java that provide it. In Java SE 5, the provided message will be augmented with information about the cause.

Parameters:
message - The message to use for the exception. This may be null if the message should be generated from the provided cause.
cause - The underlying cause for the exception. It may be null if the exception should have only a message.
Returns:
The IOException object that was created.

stringToLines

public static java.util.List<java.lang.String> stringToLines(java.lang.String s)
Converts the provided string (which may include line breaks) into a list containing the lines without the line breaks.

Parameters:
s - The string to convert into a list of its representative lines.
Returns:
A list containing the lines that comprise the given string.