org.opends.server.util
Class StaticUtils

java.lang.Object
  extended by org.opends.server.util.StaticUtils

@PublicAPI(stability=UNCOMMITTED,
           mayInstantiate=false,
           mayExtend=false,
           mayInvoke=true)
public final class StaticUtils
extends java.lang.Object

This class defines a number of static utility methods that may be used throughout the server. Note that because of the frequency with which these methods are expected to be used, very little debug logging will be performed to prevent the log from filling up with unimportant calls and to reduce the impact that debugging may have on performance.


Method Summary
static java.util.ArrayList<java.lang.String> arrayToList(java.lang.String[] stringArray)
          Retrieves an array list containing the contents of the provided array.
static void byteArrayToHexPlusAscii(java.lang.StringBuilder buffer, byte[] b, int indent)
          Appends a string representation of the provided byte array to the given buffer using the specified indent.
static void byteArrayToHexPlusAscii(java.lang.StringBuilder buffer, java.nio.ByteBuffer b, int indent)
          Appends a string representation of the remaining unread data in the provided byte buffer to the given buffer using the specified indent.
static java.lang.String bytesToColonDelimitedHex(byte[] b)
          Retrieves a string representation of the contents of the provided byte array using hexadecimal characters and a colon between each byte.
static java.lang.String bytesToHex(byte[] b)
          Retrieves a string representation of the contents of the provided byte array using hexadecimal characters and a space between each byte.
static java.lang.String bytesToHex(java.nio.ByteBuffer b)
          Retrieves a string representation of the contents of the provided byte buffer using hexadecimal characters and a space between each byte.
static java.lang.String bytesToHexNoSpace(byte[] b)
          Retrieves a string representation of the contents of the provided byte array using hexadecimal characters with no space between each byte.
static char byteToASCII(byte b)
          Retrieves the printable ASCII representation of the provided byte.
static java.lang.String byteToBinary(byte b)
          Retrieves a binary representation of the provided byte.
static java.lang.String byteToHex(byte b)
          Retrieves a string representation of the provided byte in hexadecimal.
static java.lang.String byteToLowerHex(byte b)
          Retrieves a string representation of the provided byte in hexadecimal.
static void checkOnlyOneArgPresent(Argument... args)
          Checks that no more that one of a set of arguments is present.
static java.lang.String collectionToString(java.util.Collection<?> collection, java.lang.String separator)
          Creates a string representation of the elements in the collection separated by separator.
static int compare(byte[] a, byte[] a2)
          Compare two byte arrays for order.
static Entry createEntry(DN dn)
          Creates a new, blank entry with the given DN.
static int exec(java.lang.String command, java.lang.String[] args, java.io.File workingDirectory, java.util.Map<java.lang.String,java.lang.String> environment, java.util.List<java.lang.String> output)
          Executes the specified command on the system and captures its output.
static int filterExitCode(int exitCode)
          Filters the provided value to ensure that it is appropriate for use as an exit code.
static java.lang.String formatDateTimeString(java.util.Date date)
          Formats a Date to String representation in "yyyyMMddHHmmss'Z'".
static java.lang.String getBacktrace()
          Retrieves a backtrace for the current thread consisting only of filenames and line numbers that may be useful in debugging the origin of problems that should not have happened.
static java.lang.String getBacktrace(java.lang.Throwable t)
          Retrieves a backtrace for the provided exception consisting of only filenames and line numbers that may be useful in debugging the origin of problems.
static byte[] getBytes(char[] chars)
          Construct a byte array containing the UTF-8 encoding of the provided char array.
static byte[] getBytes(java.lang.String s)
          Construct a byte array containing the UTF-8 encoding of the provided string.
static Message getExceptionMessage(java.lang.Throwable t)
          Retrieves the best human-readable message for the provided exception.
static java.io.File getFileForPath(java.lang.String path)
          Retrieves a File object corresponding to the specified path.
static byte[] hexStringToByteArray(java.lang.String hexString)
          Converts the provided hexadecimal string to a byte array.
static boolean isAddressInUse(java.net.InetAddress address, int port, boolean allowReuse)
          Indicates whether the provided TCP address is already in use.
static boolean isAlpha(char c)
          Indicates whether the provided character is an ASCII alphabetic character.
static boolean isDigit(char c)
          Indicates whether the provided character is a numeric digit.
static boolean isEmailAddress(java.lang.String addr)
          Indicates whether or not a string represents a syntactically correct email address.
static boolean isHexDigit(byte b)
          Indicates whether the provided byte represents a hexadecimal digit.
static boolean isHexDigit(char c)
          Indicates whether the provided character is a hexadecimal digit.
static boolean isRelativePath(java.lang.String path)
          Indicates whether the provided path refers to a relative path rather than an absolute path.
static boolean isValidSchemaElement(java.lang.String element, int startPos, int endPos, MessageBuilder invalidReason)
          Indicates whether the provided string contains a name or OID for a schema element like an attribute type or objectclass.
static boolean listsAreEqual(java.util.List<?> list1, java.util.List<?> list2)
          Indicates whether the two array lists are equal.
static java.lang.String[] listToArray(java.util.List<java.lang.String> stringList)
          Retrieves a string array containing the contents of the provided list of strings.
static java.lang.String listToString(java.util.List<?> list, java.lang.String separator)
          Creates a string representation of the elements in the list separated by separator.
static boolean mayUseExec()
          Indicates whether the use of the exec method will be allowed on this system.
static void moveFile(java.io.File fileToMove, java.io.File targetDirectory)
          Moves the indicated file to the specified directory by creating a new file in the target directory, copying the contents of the existing file, and removing the existing file.
static boolean needsBase64Encoding(byte[] valueBytes)
          Indicates whether the provided value needs to be base64-encoded if it is represented in LDIF form.
static boolean needsBase64Encoding(java.lang.String valueString)
          Indicates whether the provided value needs to be base64-encoded if it is represented in LDIF form.
static boolean objectsAreEqual(java.lang.Object o1, java.lang.Object o2)
          Return true if and only if o1 and o2 are both null or o1.equals(o2).
static java.util.Date parseDateTimeString(java.lang.String timeStr)
          Converts a string representing a time in "yyyyMMddHHmmss.SSS'Z'" or "yyyyMMddHHmmss" to a Date.
static boolean recursiveDelete(java.io.File file)
          Attempts to delete the specified file or directory.
static void renameFile(java.io.File fileToRename, java.io.File target)
          Renames the source file to the target file.
static Message secondsToTimeString(int numSeconds)
          Retrieves a user-friendly string that indicates the length of time (in days, hours, minutes, and seconds) in the specified number of seconds.
static void stackTraceToSingleLineString(java.lang.StringBuilder buffer, java.lang.Throwable t)
          Appends a single-line string representation of the provided exception to the given buffer.
static java.lang.String stackTraceToSingleLineString(java.lang.Throwable t)
          Retrieves a stack trace from the provided exception as a single-line string.
static void stackTraceToString(java.lang.StringBuilder buffer, java.lang.Throwable t)
          Appends a string representation of the stack trace for the provided exception to the given buffer.
static java.lang.String stackTraceToString(java.lang.Throwable t)
          Retrieves a string representation of the stack trace for the provided exception.
static void toLowerCase(byte[] b, java.lang.StringBuilder buffer, boolean trim)
          Appends a lowercase string representation of the contents of the given byte array to the provided buffer, optionally trimming leading and trailing spaces.
static java.lang.String toLowerCase(java.lang.String s)
          Retrieves a lowercase representation of the given string.
static void toLowerCase(java.lang.String s, java.lang.StringBuilder buffer)
          Appends a lowercase representation of the given string to the provided buffer.
static java.lang.StringBuilder toRFC3641StringValue(java.lang.StringBuilder builder, java.lang.String string)
          Append a string to a string builder, escaping any double quotes according to the StringValue production in RFC 3641.
static void toUpperCase(byte[] b, java.lang.StringBuilder buffer, boolean trim)
          Appends an uppercase string representation of the contents of the given byte array to the provided buffer, optionally trimming leading and trailing spaces.
static java.lang.String toUpperCase(java.lang.String s)
          Retrieves an uppercase representation of the given string.
static void toUpperCase(java.lang.String s, java.lang.StringBuilder buffer)
          Appends an uppercase representation of the given string to the provided buffer.
static java.lang.String wrapText(Message message, int width)
          Inserts line breaks into the provided buffer to wrap text at no more than the specified column width.
static java.lang.String wrapText(Message message, int width, int indent)
          Inserts line breaks into the provided buffer to wrap text at no more than the specified column width.
static java.lang.String wrapText(java.lang.String text, int width)
          Inserts line breaks into the provided buffer to wrap text at no more than the specified column width.
static java.lang.String wrapText(java.lang.String text, int width, int indent)
          Inserts line breaks into the provided buffer to wrap text at no more than the specified column width.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getBytes

public static byte[] getBytes(java.lang.String s)
Construct a byte array containing the UTF-8 encoding of the provided string. This is significantly faster than calling String.getBytes(String) for ASCII strings.

Parameters:
s - The string to convert to a UTF-8 byte array.
Returns:
Returns a byte array containing the UTF-8 encoding of the provided string.

getBytes

public static byte[] getBytes(char[] chars)
Construct a byte array containing the UTF-8 encoding of the provided char array.

Parameters:
chars - The character array to convert to a UTF-8 byte array.
Returns:
Returns a byte array containing the UTF-8 encoding of the provided char array.

byteToHex

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

Parameters:
b - The byte for which to retrieve the hexadecimal string representation.
Returns:
The string representation of the provided byte in hexadecimal.

byteToLowerHex

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

Parameters:
b - The byte for which to retrieve the hexadecimal string representation.
Returns:
The string representation of the provided byte in hexadecimal using lowercase characters.

byteToASCII

public static char byteToASCII(byte b)
Retrieves the printable ASCII representation of the provided byte.

Parameters:
b - The byte for which to retrieve the printable ASCII representation.
Returns:
The printable ASCII representation of the provided byte, or a space if the provided byte does not have printable ASCII representation.

bytesToHexNoSpace

public static java.lang.String bytesToHexNoSpace(byte[] b)
Retrieves a string representation of the contents of the provided byte array using hexadecimal characters with no space between each byte.

Parameters:
b - The byte array containing the data.
Returns:
A string representation of the contents of the provided byte array using hexadecimal characters.

bytesToHex

public static java.lang.String bytesToHex(byte[] b)
Retrieves a string representation of the contents of the provided byte array using hexadecimal characters and a space between each byte.

Parameters:
b - The byte array containing the data.
Returns:
A string representation of the contents of the provided byte array using hexadecimal characters.

bytesToColonDelimitedHex

public static java.lang.String bytesToColonDelimitedHex(byte[] b)
Retrieves a string representation of the contents of the provided byte array using hexadecimal characters and a colon between each byte.

Parameters:
b - The byte array containing the data.
Returns:
A string representation of the contents of the provided byte array using hexadecimal characters.

bytesToHex

public static java.lang.String bytesToHex(java.nio.ByteBuffer b)
Retrieves a string representation of the contents of the provided byte buffer using hexadecimal characters and a space between each byte.

Parameters:
b - The byte buffer containing the data.
Returns:
A string representation of the contents of the provided byte buffer using hexadecimal characters.

byteArrayToHexPlusAscii

public static void byteArrayToHexPlusAscii(java.lang.StringBuilder buffer,
                                           byte[] b,
                                           int indent)
Appends a string representation of the provided byte array to the given buffer using the specified indent. The data will be formatted with sixteen hex bytes in a row followed by the ASCII representation, then wrapping to a new line as necessary.

Parameters:
buffer - The buffer to which the information is to be appended.
b - The byte array containing the data to write.
indent - The number of spaces to indent the output.

byteArrayToHexPlusAscii

public static void byteArrayToHexPlusAscii(java.lang.StringBuilder buffer,
                                           java.nio.ByteBuffer b,
                                           int indent)
Appends a string representation of the remaining unread data in the provided byte buffer to the given buffer using the specified indent. The data will be formatted with sixteen hex bytes in a row followed by the ASCII representation, then wrapping to a new line as necessary. The state of the byte buffer is not changed.

Parameters:
buffer - The buffer to which the information is to be appended.
b - The byte buffer containing the data to write. The data from the position to the limit is written.
indent - The number of spaces to indent the output.

byteToBinary

public static java.lang.String byteToBinary(byte b)
Retrieves a binary representation of the provided byte. It will always be a sequence of eight zeros and/or ones.

Parameters:
b - The byte for which to retrieve the binary representation.
Returns:
The binary representation for the provided byte.

compare

public static int compare(byte[] a,
                          byte[] a2)
Compare two byte arrays for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Parameters:
a - The first byte array to be compared.
a2 - The second byte array to be compared.
Returns:
Returns a negative integer, zero, or a positive integer if the first byte array is less than, equal to, or greater than the second.

listsAreEqual

public static boolean listsAreEqual(java.util.List<?> list1,
                                    java.util.List<?> list2)
Indicates whether the two array lists are equal. They will be considered equal if they have the same number of elements, and the corresponding elements between them are equal (in the same order).

Parameters:
list1 - The first list for which to make the determination.
list2 - The second list for which to make the determination.
Returns:
true if the two array lists are equal, or false if they are not.

objectsAreEqual

public static boolean objectsAreEqual(java.lang.Object o1,
                                      java.lang.Object o2)
Return true if and only if o1 and o2 are both null or o1.equals(o2).

Parameters:
o1 - the first object to compare
o2 - the second object to compare
Returns:
true iff o1 and o2 are equal

getExceptionMessage

public static Message getExceptionMessage(java.lang.Throwable t)
Retrieves the best human-readable message for the provided exception. For exceptions defined in the OpenDS project, it will attempt to use the message (combining it with the message ID if available). For some exceptions that use encapsulation (e.g., InvocationTargetException), it will be unwrapped and the cause will be treated. For all others, the

Parameters:
t - The Throwable object for which to retrieve the message.
Returns:
The human-readable message generated for the provided exception.

stackTraceToSingleLineString

public static java.lang.String stackTraceToSingleLineString(java.lang.Throwable t)
Retrieves a stack trace from the provided exception as a single-line string.

Parameters:
t - The exception for which to retrieve the stack trace.
Returns:
A stack trace from the provided exception as a single-line string.

stackTraceToSingleLineString

public static void stackTraceToSingleLineString(java.lang.StringBuilder buffer,
                                                java.lang.Throwable t)
Appends a single-line string representation of the provided exception to the given buffer.

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

stackTraceToString

public static java.lang.String stackTraceToString(java.lang.Throwable t)
Retrieves a string representation of the stack trace for the provided exception.

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

stackTraceToString

public static void stackTraceToString(java.lang.StringBuilder buffer,
                                      java.lang.Throwable t)
Appends a string representation of the stack trace for the provided exception to the given buffer.

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

getBacktrace

public static java.lang.String getBacktrace()
Retrieves a backtrace for the current thread consisting only of filenames and line numbers that may be useful in debugging the origin of problems that should not have happened. Note that this may be an expensive operation to perform, so it should only be used for error conditions or debugging.

Returns:
A backtrace for the current thread.

getBacktrace

public static java.lang.String getBacktrace(java.lang.Throwable t)
Retrieves a backtrace for the provided exception consisting of only filenames and line numbers that may be useful in debugging the origin of problems. This is less expensive than the call to getBacktrace without any arguments if an exception has already been thrown.

Parameters:
t - The exception for which to obtain the backtrace.
Returns:
A backtrace from the provided exception.

isDigit

public static boolean isDigit(char c)
Indicates whether the provided character is a numeric digit.

Parameters:
c - The character for which to make the determination.
Returns:
true if the provided character represents a numeric digit, or false if not.

isAlpha

public static boolean isAlpha(char c)
Indicates whether the provided character is an ASCII alphabetic character.

Parameters:
c - The character for which to make the determination.
Returns:
true if the provided value is an uppercase or lowercase ASCII alphabetic character, or false if it is not.

isHexDigit

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

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

isHexDigit

public static boolean isHexDigit(byte b)
Indicates whether the provided byte represents a hexadecimal digit.

Parameters:
b - The byte for which to make the determination.
Returns:
true if the provided byte represents a hexadecimal digit, or false if not.

hexStringToByteArray

public static byte[] hexStringToByteArray(java.lang.String hexString)
                                   throws java.text.ParseException
Converts the provided hexadecimal string to a byte array.

Parameters:
hexString - The hexadecimal string to convert to a byte array.
Returns:
The byte array containing the binary representation of the provided hex string.
Throws:
java.text.ParseException - If the provided string contains invalid hexadecimal digits or does not contain an even number of digits.

needsBase64Encoding

public static boolean needsBase64Encoding(byte[] valueBytes)
Indicates whether the provided value needs to be base64-encoded if it is represented in LDIF form.

Parameters:
valueBytes - The binary representation of the attribute value for which to make the determination.
Returns:
true if the value needs to be base64-encoded if it is represented in LDIF form, or false if not.

needsBase64Encoding

public static boolean needsBase64Encoding(java.lang.String valueString)
Indicates whether the provided value needs to be base64-encoded if it is represented in LDIF form.

Parameters:
valueString - The string representation of the attribute value for which to make the determination.
Returns:
true if the value needs to be base64-encoded if it is represented in LDIF form, or false if not.

mayUseExec

public static boolean mayUseExec()
Indicates whether the use of the exec method will be allowed on this system. It will be allowed by default, but that capability will be removed if the org.opends.server.DisableExec system property is set and has any value other than "false", "off", "no", or "0".

Returns:
true if the use of the exec method should be allowed, or false if it should not be allowed.

exec

public static int exec(java.lang.String command,
                       java.lang.String[] args,
                       java.io.File workingDirectory,
                       java.util.Map<java.lang.String,java.lang.String> environment,
                       java.util.List<java.lang.String> output)
                throws java.io.IOException,
                       java.lang.SecurityException,
                       java.lang.InterruptedException
Executes the specified command on the system and captures its output. This will not return until the specified process has completed.

Parameters:
command - The command to execute.
args - The set of arguments to provide to the command.
workingDirectory - The working directory to use for the command, or null if the default directory should be used.
environment - The set of environment variables that should be set when executing the command, or null if none are needed.
output - The output generated by the command while it was running. This will include both standard output and standard error. It may be null if the output does not need to be captured.
Returns:
The exit code for the command.
Throws:
java.io.IOException - If an I/O problem occurs while trying to execute the command.
java.lang.SecurityException - If the security policy will not allow the command to be executed.
java.lang.InterruptedException - If the current thread is interrupted by another thread while it is waiting, then the wait is ended and an InterruptedException is thrown.

isValidSchemaElement

public static boolean isValidSchemaElement(java.lang.String element,
                                           int startPos,
                                           int endPos,
                                           MessageBuilder invalidReason)
Indicates whether the provided string contains a name or OID for a schema element like an attribute type or objectclass.

Parameters:
element - The string containing the substring for which to make the determination.
startPos - The position of the first character that is to be checked.
endPos - The position of the first character after the start position that is not to be checked.
invalidReason - The buffer to which the invalid reason is to be appended if a problem is found.
Returns:
true if the provided string contains a valid name or OID for a schema element, or false if it does not.

isAddressInUse

public static boolean isAddressInUse(java.net.InetAddress address,
                                     int port,
                                     boolean allowReuse)
Indicates whether the provided TCP address is already in use.

Parameters:
address - IP address of the TCP address for which to make the determination.
port - TCP port number of the TCP address for which to make the determination.
allowReuse - Whether or not TCP address reuse is allowed when making the determination.
Returns:
true if the provided TCP address is already in use, or false otherwise.

toLowerCase

public static java.lang.String toLowerCase(java.lang.String s)
Retrieves a lowercase representation of the given string. This implementation presumes that the provided string will contain only ASCII characters and is optimized for that case. However, if a non-ASCII character is encountered it will fall back on a more expensive algorithm that will work properly for non-ASCII characters.

Parameters:
s - The string for which to obtain the lowercase representation.
Returns:
The lowercase representation of the given string.

toLowerCase

public static void toLowerCase(java.lang.String s,
                               java.lang.StringBuilder buffer)
Appends a lowercase representation of the given string to the provided buffer. This implementation presumes that the provided string will contain only ASCII characters and is optimized for that case. However, if a non-ASCII character is encountered it will fall back on a more expensive algorithm that will work properly for non-ASCII characters.

Parameters:
s - The string for which to obtain the lowercase representation.
buffer - The buffer to which the lowercase form of the string should be appended.

toLowerCase

public static void toLowerCase(byte[] b,
                               java.lang.StringBuilder buffer,
                               boolean trim)
Appends a lowercase string representation of the contents of the given byte array to the provided buffer, optionally trimming leading and trailing spaces. This implementation presumes that the provided string will contain only ASCII characters and is optimized for that case. However, if a non-ASCII character is encountered it will fall back on a more expensive algorithm that will work properly for non-ASCII characters.

Parameters:
b - The byte array for which to obtain the lowercase string representation.
buffer - The buffer to which the lowercase form of the string should be appended.
trim - Indicates whether leading and trailing spaces should be omitted from the string representation.

toUpperCase

public static java.lang.String toUpperCase(java.lang.String s)
Retrieves an uppercase representation of the given string. This implementation presumes that the provided string will contain only ASCII characters and is optimized for that case. However, if a non-ASCII character is encountered it will fall back on a more expensive algorithm that will work properly for non-ASCII characters.

Parameters:
s - The string for which to obtain the uppercase representation.
Returns:
The uppercase representation of the given string.

toUpperCase

public static void toUpperCase(java.lang.String s,
                               java.lang.StringBuilder buffer)
Appends an uppercase representation of the given string to the provided buffer. This implementation presumes that the provided string will contain only ASCII characters and is optimized for that case. However, if a non-ASCII character is encountered it will fall back on a more expensive algorithm that will work properly for non-ASCII characters.

Parameters:
s - The string for which to obtain the uppercase representation.
buffer - The buffer to which the uppercase form of the string should be appended.

toUpperCase

public static void toUpperCase(byte[] b,
                               java.lang.StringBuilder buffer,
                               boolean trim)
Appends an uppercase string representation of the contents of the given byte array to the provided buffer, optionally trimming leading and trailing spaces. This implementation presumes that the provided string will contain only ASCII characters and is optimized for that case. However, if a non-ASCII character is encountered it will fall back on a more expensive algorithm that will work properly for non-ASCII characters.

Parameters:
b - The byte array for which to obtain the uppercase string representation.
buffer - The buffer to which the uppercase form of the string should be appended.
trim - Indicates whether leading and trailing spaces should be omitted from the string representation.

toRFC3641StringValue

public static java.lang.StringBuilder toRFC3641StringValue(java.lang.StringBuilder builder,
                                                           java.lang.String string)
Append a string to a string builder, escaping any double quotes according to the StringValue production in RFC 3641.

In RFC 3641 the StringValue production looks like this:

    StringValue       = dquote *SafeUTF8Character dquote
    dquote            = %x22 ; " (double quote)
    SafeUTF8Character = %x00-21 / %x23-7F /   ; ASCII minus dquote
                        dquote dquote /       ; escaped double quote
                        %xC0-DF %x80-BF /     ; 2 byte UTF-8 character
                        %xE0-EF 2(%x80-BF) /  ; 3 byte UTF-8 character
                        %xF0-F7 3(%x80-BF)    ; 4 byte UTF-8 character
 

That is, strings are surrounded by double-quotes and any internal double-quotes are doubled up.

Parameters:
builder - The string builder.
string - The string to escape and append.
Returns:
Returns the string builder.

listToArray

public static java.lang.String[] listToArray(java.util.List<java.lang.String> stringList)
Retrieves a string array containing the contents of the provided list of strings.

Parameters:
stringList - The string list to convert to an array.
Returns:
A string array containing the contents of the provided list of strings.

listToString

public static java.lang.String listToString(java.util.List<?> list,
                                            java.lang.String separator)
Creates a string representation of the elements in the list separated by separator.

Parameters:
list - the list to print
separator - to use between elements
Returns:
String representing the list

collectionToString

public static java.lang.String collectionToString(java.util.Collection<?> collection,
                                                  java.lang.String separator)
Creates a string representation of the elements in the collection separated by separator.

Parameters:
collection - to print
separator - to use between elements
Returns:
String representing the collection

arrayToList

public static java.util.ArrayList<java.lang.String> arrayToList(java.lang.String[] stringArray)
Retrieves an array list containing the contents of the provided array.

Parameters:
stringArray - The string array to convert to an array list.
Returns:
An array list containing the contents of the provided array.

recursiveDelete

public static boolean recursiveDelete(java.io.File file)
Attempts to delete the specified file or directory. If it is a directory, then any files or subdirectories that it contains will be recursively deleted as well.

Parameters:
file - The file or directory to be removed.
Returns:
true if the specified file and any subordinates are all successfully removed, or false if at least one element in the subtree could not be removed.

moveFile

public static void moveFile(java.io.File fileToMove,
                            java.io.File targetDirectory)
                     throws java.io.IOException
Moves the indicated file to the specified directory by creating a new file in the target directory, copying the contents of the existing file, and removing the existing file. The file to move must exist and must be a file. The target directory must exist, must be a directory, and must not be the directory in which the file currently resides.

Parameters:
fileToMove - The file to move to the target directory.
targetDirectory - The directory into which the file should be moved.
Throws:
java.io.IOException - If a problem occurs while attempting to move the file.

renameFile

public static void renameFile(java.io.File fileToRename,
                              java.io.File target)
                       throws java.io.IOException
Renames the source file to the target file. If the target file exists it is first deleted. The rename and delete operation return values are checked for success and if unsuccessful, this method throws an exception.

Parameters:
fileToRename - The file to rename.
target - The file to which fileToRename will be moved.
Throws:
java.io.IOException - If a problem occurs while attempting to rename the file. On the Windows platform, this typically indicates that the file is in use by this or another application.

isRelativePath

public static boolean isRelativePath(java.lang.String path)
Indicates whether the provided path refers to a relative path rather than an absolute path.

Parameters:
path - The path string for which to make the determination.
Returns:
true if the provided path is relative, or false if it is absolute.

getFileForPath

public static java.io.File getFileForPath(java.lang.String path)
Retrieves a File object corresponding to the specified path. If the given path is an absolute path, then it will be used. If the path is relative, then it will be interpreted as if it were relative to the Directory Server root.

Parameters:
path - The path string to be retrieved as a File
Returns:
A File object that corresponds to the specified path.

createEntry

public static Entry createEntry(DN dn)
Creates a new, blank entry with the given DN. It will contain only the attribute(s) contained in the RDN. The choice of objectclasses will be based on the RDN attribute. If there is a single RDN attribute, then the following mapping will be used:

Any other single RDN attribute types, or any case in which there are multiple RDN attributes, will use the untypedObject objectclass. If the RDN includes one or more attributes that are not allowed in the untypedObject objectclass, then the extensibleObject class will also be added. Note that this method cannot be used to generate an entry with an empty or null DN.

Parameters:
dn - The DN to use for the entry.
Returns:
The entry created with the provided DN.

secondsToTimeString

public static Message secondsToTimeString(int numSeconds)
Retrieves a user-friendly string that indicates the length of time (in days, hours, minutes, and seconds) in the specified number of seconds.

Parameters:
numSeconds - The number of seconds to be converted to a more user-friendly value.
Returns:
The user-friendly representation of the specified number of seconds.

wrapText

public static java.lang.String wrapText(Message message,
                                        int width)
Inserts line breaks into the provided buffer to wrap text at no more than the specified column width. Wrapping will only be done at space boundaries and if there are no spaces within the specified width, then wrapping will be performed at the first space after the specified column.

Parameters:
message - The message to be wrapped.
width - The maximum number of characters to allow on a line if there is a suitable breaking point.
Returns:
The wrapped text.

wrapText

public static java.lang.String wrapText(java.lang.String text,
                                        int width)
Inserts line breaks into the provided buffer to wrap text at no more than the specified column width. Wrapping will only be done at space boundaries and if there are no spaces within the specified width, then wrapping will be performed at the first space after the specified column.

Parameters:
text - The text to be wrapped.
width - The maximum number of characters to allow on a line if there is a suitable breaking point.
Returns:
The wrapped text.

wrapText

public static java.lang.String wrapText(Message message,
                                        int width,
                                        int indent)
Inserts line breaks into the provided buffer to wrap text at no more than the specified column width. Wrapping will only be done at space boundaries and if there are no spaces within the specified width, then wrapping will be performed at the first space after the specified column. In addition each line will be indented by the specified amount.

Parameters:
message - The message to be wrapped.
width - The maximum number of characters to allow on a line if there is a suitable breaking point (including any indentation).
indent - The number of columns to indent each line.
Returns:
The wrapped text.

wrapText

public static java.lang.String wrapText(java.lang.String text,
                                        int width,
                                        int indent)
Inserts line breaks into the provided buffer to wrap text at no more than the specified column width. Wrapping will only be done at space boundaries and if there are no spaces within the specified width, then wrapping will be performed at the first space after the specified column. In addition each line will be indented by the specified amount.

Parameters:
text - The text to be wrapped.
width - The maximum number of characters to allow on a line if there is a suitable breaking point (including any indentation).
indent - The number of columns to indent each line.
Returns:
The wrapped text.

filterExitCode

public static int filterExitCode(int exitCode)
Filters the provided value to ensure that it is appropriate for use as an exit code. Exit code values are generally only allowed to be between 0 and 255, so any value outside of this range will be converted to 255, which is the typical exit code used to indicate an overflow value.

Parameters:
exitCode - The exit code value to be processed.
Returns:
An integer value between 0 and 255, inclusive. If the provided exit code was already between 0 and 255, then the original value will be returned. If the provided value was out of this range, then 255 will be returned.

checkOnlyOneArgPresent

public static void checkOnlyOneArgPresent(Argument... args)
                                   throws ArgumentException
Checks that no more that one of a set of arguments is present. This utility should be used after argument parser has parsed a set of arguments.

Parameters:
args - to test for the presence of more than one
Throws:
ArgumentException - if more than one of args is present and containing an error message identifying the arguments in violation

parseDateTimeString

public static java.util.Date parseDateTimeString(java.lang.String timeStr)
                                          throws java.text.ParseException
Converts a string representing a time in "yyyyMMddHHmmss.SSS'Z'" or "yyyyMMddHHmmss" to a Date.

Parameters:
timeStr - string formatted appropriately
Returns:
Date object; null if timeStr is null
Throws:
java.text.ParseException - if there was a problem converting the string to a Date.

formatDateTimeString

public static java.lang.String formatDateTimeString(java.util.Date date)
Formats a Date to String representation in "yyyyMMddHHmmss'Z'".

Parameters:
date - to format; null if date is null
Returns:
string representation of the date

isEmailAddress

public static boolean isEmailAddress(java.lang.String addr)
Indicates whether or not a string represents a syntactically correct email address.

Parameters:
addr - to validate
Returns:
boolean where true indicates that the string is a syntactically correct email address