Package com.unboundid.util
Class StaticUtils
java.lang.Object
com.unboundid.util.StaticUtils
This class provides a number of static utility functions.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe end-of-line marker for the platform on which the LDAP SDK is currently running.static final byte[]A byte array containing the end-of-line marker for the platform on which the LDAP SDK is currently running.static final byte[]A byte array containing the end-of-line marker that consists of a carriage return character followed by a line feed character, as used on Windows systems.static final byte[]A byte array containing the end-of-line marker that consists of just the line feed character, as used on UNIX-based systems.static final StringThe end-of-line marker that consists of a carriage return character followed by a line feed character, as used on Windows systems.static final StringThe end-of-line marker that consists of just the line feed character, as used on UNIX-based systems.static final byte[]A pre-allocated byte array containing zero bytes.static final char[]A pre-allocated empty character array.static final Control[]A pre-allocated empty control array.static final int[]A pre-allocated empty integer array.static final String[]A pre-allocated empty string array.static final intThe width of the terminal window, in columns. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> booleanarraysEqualOrderIndependent(T[] a1, T[] a2) Indicates whether the provided arrays have the same elements, ignoring the order in which they appear.static booleanbothNullOrEqual(Object o1, Object o2) Indicates whether both of the provided objects arenullor both are logically equal (using theequalsmethod).static booleanbothNullOrEqualIgnoreCase(String s1, String s2) Indicates whether both of the provided strings arenullor both are logically equal ignoring differences in capitalization (using theequalsIgnoreCasemethod).static byte[]byteArray(int... bytes) Creates a byte array from the provided integer values.static voidbyteArrayToCode(byte[] array, StringBuilder buffer) Appends the Java code that may be used to create the provided byte array to the given buffer.static Stringcapitalize(String s) Capitalizes the provided string.static Stringcapitalize(String s, boolean allWords) Capitalizes the provided string.static StringThis method returns a form of the provided argument that is safe to use on the command line for the local platform.static StringclearSystemProperty(String name) Attempts to clear the value of the specified system property.static intcomputeMapCapacity(int expectedItemCount) Computes the capacity that should be used for a map or a set with the expected number of elements, which can help avoid the need to re-hash or re-balance the map if too many items are added.static StringconcatenateStrings(String... a) Retrieves a single string which is a concatenation of all of the provided strings.static StringconcatenateStrings(String beforeList, String beforeElement, String betweenElements, String afterElement, String afterList, String... a) Retrieves a single string which is a concatenation of all of the provided strings.static StringconcatenateStrings(String beforeList, String beforeElement, String betweenElements, String afterElement, String afterList, List<String> l) Retrieves a single string which is a concatenation of all of the provided strings.static StringRetrieves a single string which is a concatenation of all of the provided strings.static FileconstructPath(File baseDirectory, String... pathElements) Constructs aFileobject from the provided path.static IOExceptioncreateIOExceptionWithCause(String message, Throwable cause) Creates a newIOExceptionwith a cause.static DateDecodes the provided string as a timestamp in generalized time format.static DatedecodeRFC3339Time(String timestamp) Decodes the provided string as a timestamp encoded in the ISO 8601 format described in RFC 3339.static UUIDdecodeUUID(byte[] b) Decodes the value of the provided byte array as a Java UUID.static StringencodeGeneralizedTime(long timestamp) Encodes the provided timestamp in generalized time format.static StringEncodes the provided date in generalized time format.static StringencodeRFC3339Time(long timestamp) Encodes the provided timestamp to the ISO 8601 format described in RFC 3339.static StringEncodes the provided timestamp to the ISO 8601 format described in RFC 3339.static byte[]encodeUUID(UUID uuid) Encodes the provided UUID to a byte array containing its 128-bit representation.static byte[]Retrieves the bytes that correspond to the provided hexadecimal string.static Set<InetAddress> getAllLocalAddresses(NameResolver nameResolver) Attempts to determine all addresses associated with the local system, including loopback addresses.static Set<InetAddress> getAllLocalAddresses(NameResolver nameResolver, boolean includeLoopback) Attempts to determine all addresses associated with the local system, optionally including loopback addresses.getAvailableCanonicalHostNames(NameResolver nameResolver, Collection<InetAddress> addresses) Retrieves the canonical host names for the provided set ofInetAddressobjects.static StringRetrieves a single-line string representation of the stack trace for the current thread.static byte[]Retrieves a UTF-8 byte representation of the provided string.static byte[]getBytesForCodePoint(int codePoint) Retrieves a byte array containing the UTF-8 representation of the bytes that comprise the provided Unicode code point.static StringgetCanonicalHostNameIfAvailable(NameResolver nameResolver, InetAddress address) Retrieves the canonical host name for the provided address, if it can be resolved to a name.static int[]Retrieves an array of the code points that comprise the provided string.static StringRetrieves the string that should be appended to the end of all but the last line of a multi-line command to indicate that the command continues onto the next line.static StringgetEnvironmentVariable(String name) Retrieves the value of the specified environment variable.static StringgetEnvironmentVariable(String name, String defaultValue) Retrieves the value of the specified environment variable.Retrieves a map of all environment variables defined in the JVM's process.static StringRetrieves a string representation of the providedThrowableobject suitable for use in a message.static StringgetExceptionMessage(Throwable t, boolean includeCause, boolean includeStackTrace) Retrieves a string representation of the providedThrowableobject suitable for use in a message.Retrieves a set containing the base names (in all lowercase characters) of any attributes that should be considered sensitive for the purposes of thetoCodemethods.static StringgetStackTrace(StackTraceElement[] elements) Returns a single-line string representation of the stack trace.static voidgetStackTrace(StackTraceElement[] elements, StringBuilder buffer) Appends a single-line string representation of the stack trace to the given buffer.static voidgetStackTrace(StackTraceElement[] elements, StringBuilder buffer, int maxPreSDKFrames) Appends a single-line string representation of the stack trace to the given buffer.static StringRetrieves a single-line string representation of the stack trace for the providedThrowable.static voidgetStackTrace(Throwable t, StringBuilder buffer) Appends a single-line string representation of the stack trace for the providedThrowableto the given buffer.static PropertiesgetSystemProperties(String... propertyNames) Retrieves the set of currently defined system properties.static StringgetSystemProperty(String name) Retrieves the value of the specified system property.static StringgetSystemProperty(String name, String defaultValue) Retrieves the value of the specified system property.static StringgetUnqualifiedClassName(Class<?> c) Retrieves the unqualified name (i.e., the name without package information) for the provided class.static TimeZoneRetrieves aTimeZoneobject that represents the UTC (universal coordinated time) time zone.static <T> HashSet<T> hashSetOf(T... items) Creates aHashSetcontaining the provided items.static voidhexEncode(char c, StringBuilder buffer) Appends a hex-encoded representation of the provided character to the given buffer.static voidhexEncode(int codePoint, StringBuilder buffer) Appends a hex-encoded representation of the provided code point to the given buffer.static booleanisASCIIString(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 booleanIndicates whether the contents of the provided string represent an ASCII string, which is also known in LDAP terminology as an IA5 string.static booleanisHex(char c) Indicates whether the provided character is a valid hexadecimal digit.static booleanisIANAReservedIPAddress(InetAddress address, boolean includePrivateUseNetworkAddresses) Indicates whether the provided address is marked as reserved in the IANA IPv4 address space registry at https://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.txt or the IPv6 address space registry at https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.txt.static booleanisIANAReservedIPv4Address(Inet4Address address, boolean includePrivateUseNetworkAddresses) Indicates whether the provided address is marked as reserved in the IANA IPv4 address space registry at https://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.txt.static booleanisIANAReservedIPv6Address(Inet6Address address, boolean includePrivateUseNetworkAddresses) Indicates whether the provided address is marked as reserved in the IANA IPv6 address space registry at https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.txt.static booleanisLikelyDisplayableCharacter(int codePoint) Indicates whether the specified Unicode code point represents a character that is believed to be displayable.static booleanIndicates whether the provided string is comprised entirely of characters that are believed to be displayable (as determined by theisLikelyDisplayableCharacter(int)method).static booleanisLikelyDisplayableUTF8String(byte[] b) Indicates whether the provided byte array represents a valid UTF-8 string that is comprised entirely of characters that are believed to be displayable (as determined by theisLikelyDisplayableCharacter(int)method).static booleanIndicates whether the provided string is a valid numeric OID.static booleanisPrintable(char c) Indicates whether the provided character is a printable ASCII character, as per RFC 4517 section 3.2.static booleanisPrintableString(byte[] b) Indicates whether the contents of the provided byte array represent a printable LDAP string, as per RFC 4517 section 3.2.static booleanIndicates whether the provided string represents a printable LDAP string, as per RFC 4517 section 3.2.static booleanIndicates whether the provided attribute name should be considered a sensitive attribute for the purposes oftoCodemethods.static booleanisValidUTF8(byte[] b) Indicates whether the contents of the provided array represent a valid UTF-8 string, which may or may not contain non-ASCII characters.static booleanisValidUTF8WithNonASCIICharacters(byte[] b) Indicates whether the contents of the provided array represent a valid UTF-8 string that contains at least one non-ASCII character (and may contain zero or more ASCII characters).static booleanReturnstrueif and only if the current process is running on a Windows-based operating system.static booleanIndicates whether the unit tests are currently running in this JVM.static StringlinesToString(CharSequence... lines) Creates a string that is a concatenation of all of the provided lines, with a line break (using the end-of-line sequence appropriate for the underlying platform) after each line (including the last line).static StringlinesToString(List<? extends CharSequence> lines) Creates a string that is a concatenation of all of the provided lines, with a line break (using the end-of-line sequence appropriate for the underlying platform) after each line (including the last line).static <T> LinkedHashSet<T> linkedHashSetOf(T... items) Creates aLinkedHashSetcontaining the provided items.static <K,V> Map <K, V> mapOf(K key, V value) Creates an unmodifiable map containing the provided items.static <K,V> Map <K, V> mapOf(K key1, V value1, K key2, V value2) Creates an unmodifiable map containing the provided items.static <K,V> Map <K, V> mapOf(K key1, V value1, K key2, V value2, K key3, V value3) Creates an unmodifiable map containing the provided items.static <K,V> Map <K, V> mapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4) Creates an unmodifiable map containing the provided items.static <K,V> Map <K, V> mapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4, K key5, V value5) Creates an unmodifiable map containing the provided items.static <K,V> Map <K, V> mapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4, K key5, V value5, K key6, V value6) Creates an unmodifiable map containing the provided items.static <K,V> Map <K, V> mapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4, K key5, V value5, K key6, V value6, K key7, V value7) Creates an unmodifiable map containing the provided items.static <K,V> Map <K, V> mapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4, K key5, V value5, K key6, V value6, K key7, V value7, K key8, V value8) Creates an unmodifiable map containing the provided items.static <K,V> Map <K, V> mapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4, K key5, V value5, K key6, V value6, K key7, V value7, K key8, V value8, K key9, V value9) Creates an unmodifiable map containing the provided items.static <K,V> Map <K, V> mapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4, K key5, V value5, K key6, V value6, K key7, V value7, K key8, V value8, K key9, V value9, K key10, V value10) Creates an unmodifiable map containing the provided items.static <T> Map<T, T> mapOf(T... items) Creates an unmodifiable map containing the provided items.static <K,V> Map <K, V> mapOfObjectPairs(ObjectPair<K, V>... items) Creates an unmodifiable map containing the provided items.static StringmillisToHumanReadableDuration(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 longmillisToNanos(long millis) Converts the provided number of milliseconds to nanoseconds.static longnanosToMillis(long nanos) Converts the provided number of nanoseconds to milliseconds.static intDetermines the number of bytes in a UTF-8 character that starts with the given byte.static StringrandomAlphabeticString(int length, boolean secure) Retrieves a string containing the specified number of randomly selected ASCII letters.static StringrandomAlphanumericString(int length, boolean secure) Retrieves a string containing the specified number of randomly selected ASCII alphanumeric characters.static byte[]randomBytes(int numBytes, boolean secure) Retrieves a byte array with the specified number of randomly selected bytes.static intrandomInt(int lowerBound, int upperBound, boolean secure) Retrieves a randomly selected integer between the given upper and lower bounds.static StringrandomNumericString(int length, boolean secure) Retrieves a string containing the specified number of randomly selected ASCII numeric digits.static StringrandomString(int length, char[] allowedChars, boolean secure) Retrieves a string containing the specified number of randomly selected characters from the given set.static StringreadFileAsString(File file, boolean includeFinalLineBreak) Reads the contents of the specified file as a string.static StringreadFileAsString(String path, boolean includeFinalLineBreak) Reads the contents of the specified file as a string.static byte[]readFileBytes(File file) Reads the bytes that comprise the specified file.static byte[]readFileBytes(String path) Reads the bytes that comprise the specified file.readFileLines(File file) Reads the lines that comprise the specified file.readFileLines(String path) Reads the lines that comprise the specified file.static voidrethrowIfError(Throwable throwable) Re-throws the providedThrowableinstance only if it is anError; otherwise, this method will return without taking any action.static voidrethrowIfErrorOrRuntimeException(Throwable throwable) Re-throws the providedThrowableinstance only if it is anErroror aRuntimeExceptioninstance; otherwise, this method will return without taking any action.static StringsecondsToHumanReadableDuration(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 voidsetLoggerLevel(Logger logger, Level logLevel) Attempts to set the desired log level for the specified logger.static voidsetLogHandlerLevel(Handler logHandler, Level logLevel) Attempts to set the desired log level for the specified log handler.static <T> Set<T> setOf(T... items) Creates an unmodifiable set containing the provided items.static voidsetSensitiveToCodeAttributes(String... names) Specifies the names of any attributes that should be considered sensitive for the purposes of thetoCodemethods.static voidSpecifies the names of any attributes that should be considered sensitive for the purposes of thetoCodemethods.static StringsetSystemProperty(String name, String value) Attempts to set the value of the specified system property.static StringsetSystemPropertyIfNotAlreadyDefined(String name, String value) Attempts to set the value of the specified system property, but only if the specified property does not already have a value.static booleanstringsEqualIgnoreCaseOrderIndependent(String[] a1, String[] a2) Indicates whether the provided string arrays have the same elements, ignoring the order in which they appear and differences in capitalization.Converts the provided string (which may include line breaks) into a list containing the lines without the line breaks.static voidthrowErrorOrRuntimeException(Throwable throwable) Throws anErroror aRuntimeExceptionbased on the providedThrowableobject.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 <T> T[]toArray(Collection<T> collection, Class<T> type) Retrieves an array containing the elements of the provided collection.static StringtoHex(byte b) Retrieves a hexadecimal representation of the provided byte.static StringtoHex(byte[] b) Retrieves a hexadecimal representation of the contents of the provided byte array.static voidtoHex(byte[] b, StringBuilder buffer) Retrieves a hexadecimal representation of the contents of the provided byte array.static voidtoHex(byte[] b, String delimiter, StringBuilder buffer) Retrieves a hexadecimal representation of the contents of the provided byte array.static voidtoHex(byte b, ByteStringBuffer buffer) Appends a hexadecimal representation of the provided byte to the given buffer.static voidtoHex(byte b, StringBuilder buffer) Appends a hexadecimal representation of the provided byte to the given buffer.static StringtoHexPlusASCII(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 voidtoHexPlusASCII(byte[] array, int indent, 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 StringRetrieves a version of the provided string with the first character converted to lowercase but all other characters retaining their original capitalization.static <T> List<T> toList(T[] array) Creates a modifiable list with all of the items of the provided array in the same order.static StringRetrieves an all-lowercase version of the provided string.static <T> List<T> toNonNullList(T[] array) Creates a modifiable list with all of the items of the provided array in the same order.static StringRetrieves an all-uppercase version of the provided string.static StringtoUTF8String(byte[] b) Retrieves a string generated from the provided byte array using the UTF-8 encoding.static StringtoUTF8String(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 <T> TreeSet<T> treeSetOf(T... items) Creates aTreeSetcontaining the provided items.static StringtrimInterfaceNameFromHostAddress(String hostAddress) Retrieves a version of the provided host address with the interface name stripped off.static StringTrims only leading spaces from the provided string, leaving any trailing spaces intact.static StringTrims only trailing spaces from the provided string, leaving any leading spaces intact.static booleanunicodeStringsAreEquivalent(String s1, String s2) Indicates whether the provided strings represent an equivalent sequence of Unicode characters.static booleanutf8StringsAreEquivalent(byte[] b1, byte[] b2) Indicates whether the provided byte arrays represent UTF-8 strings that have an equivalent sequence of Unicode characters.Wraps the contents of the specified line using the given width.Wraps the contents of the specified line using the given width.static voidWrites the provided bytes to the specified file.static voidwriteFile(File file, CharSequence... lines) Writes the provided lines to the specified file, with each followed by an appropriate end-of-line marker for the current platform.static voidwriteFile(File file, List<? extends CharSequence> lines) Writes the provided lines to the specified file, with each followed by an appropriate end-of-line marker for the current platform.static voidWrites the provided bytes to the specified file.static voidwriteFile(String path, CharSequence... lines) Writes the provided lines to the specified file, with each followed by an appropriate end-of-line marker for the current platform.static voidwriteFile(String path, List<? extends CharSequence> lines) Writes the provided lines to the specified file, with each followed by an appropriate end-of-line marker for the current platform.
-
Field Details
-
NO_BYTES
A pre-allocated byte array containing zero bytes. -
NO_CHARS
A pre-allocated empty character array. -
NO_CONTROLS
A pre-allocated empty control array. -
NO_INTS
A pre-allocated empty integer array. -
NO_STRINGS
A pre-allocated empty string array. -
EOL
The end-of-line marker for the platform on which the LDAP SDK is currently running. -
EOL_CR_LF
The end-of-line marker that consists of a carriage return character followed by a line feed character, as used on Windows systems.- See Also:
-
EOL_LF
The end-of-line marker that consists of just the line feed character, as used on UNIX-based systems.- See Also:
-
EOL_BYTES
A byte array containing the end-of-line marker for the platform on which the LDAP SDK is currently running. -
EOL_BYTES_CR_LF
A byte array containing the end-of-line marker that consists of a carriage return character followed by a line feed character, as used on Windows systems. -
EOL_BYTES_LF
A byte array containing the end-of-line marker that consists of just the line feed character, as used on UNIX-based systems. -
TERMINAL_WIDTH_COLUMNS
The width of the terminal window, in columns.
-
-
Method Details
-
getSystemProperties
Retrieves the set of currently defined system properties. If possible, this will simply return the result of a call toSystem.getProperties. However, the LDAP SDK is known to be used in environments where a security manager prevents setting system properties, and in that case, calls toSystem.getPropertieswill be rejected with aSecurityExceptionbecause the returned structure is mutable and could be used to alter system property values. In such cases, a new emptyPropertiesobject will be created, and may optionally be populated with the values of a specific set of named properties.- Parameters:
propertyNames- An optional set of property names whose values (if defined) should be included in thePropertiesobject that will be returned if a security manager prevents retrieving the full set of system properties. This may benullor empty if no specific properties should be retrieved.- Returns:
- The value returned by a call to
System.getPropertiesif possible, or a newly-created properties map (possibly including the values of a specified set of system properties) if it is not possible to get a mutable set of the system properties.
-
getSystemProperty
Retrieves the value of the specified system property.- Parameters:
name- The name of the system property for which to retrieve the value.- Returns:
- The value of the requested system property, or
nullif that variable was not set or its value could not be retrieved (for example, because a security manager prevents it).
-
getSystemProperty
@Nullable public static String getSystemProperty(@NotNull String name, @Nullable String defaultValue) Retrieves the value of the specified system property.- Parameters:
name- The name of the system property for which to retrieve the value.defaultValue- The default value to return if the specified system property is not set or could not be retrieved.- Returns:
- The value of the requested system property, or the provided default value if that system property was not set or its value could not be retrieved (for example, because a security manager prevents it).
-
setSystemProperty
Attempts to set the value of the specified system property. Note that this may not be permitted by some security managers, in which case the attempt will have no effect.- Parameters:
name- The name of the system property to set. It must not benull.value- The value to use for the system property. If it isnull, then the property will be cleared.- Returns:
- The former value of the system property, or
nullif it did not have a value or if it could not be set (for example, because a security manager prevents it).
-
setSystemPropertyIfNotAlreadyDefined
@NotNull public static String setSystemPropertyIfNotAlreadyDefined(@NotNull String name, @NotNull String value) Attempts to set the value of the specified system property, but only if the specified property does not already have a value. If the specified property is already set, then it will remain set to its current value.- Parameters:
name- The name of the system property to set. It must not benull.value- The value to use for the system property if it is not already set. It must not benull.- Returns:
- The existing value for the system property, if it was previously
defined, or
nullif it did not already have a value.
-
clearSystemProperty
Attempts to clear the value of the specified system property. Note that this may not be permitted by some security managers, in which case the attempt will have no effect.- Parameters:
name- The name of the System property to clear. It must not benull.- Returns:
- The former value of the system property, or
nullif it did not have a value or if it could not be set (for example, because a security manager prevents it).
-
getEnvironmentVariables
Retrieves a map of all environment variables defined in the JVM's process.- Returns:
- A map of all environment variables defined in the JVM's process, or an empty map if no environment variables are set or the actual set could not be retrieved (for example, because a security manager prevents it).
-
getEnvironmentVariable
Retrieves the value of the specified environment variable.- Parameters:
name- The name of the environment variable for which to retrieve the value.- Returns:
- The value of the requested environment variable, or
nullif that variable was not set or its value could not be retrieved (for example, because a security manager prevents it).
-
getEnvironmentVariable
@Nullable public static String getEnvironmentVariable(@NotNull String name, @Nullable String defaultValue) Retrieves the value of the specified environment variable.- Parameters:
name- The name of the environment variable for which to retrieve the value.defaultValue- The default value to use if the specified environment variable is not set. It may benullif no default should be used.- Returns:
- The value of the requested environment variable, or
nullif that variable was not set or its value could not be retrieved (for example, because a security manager prevents it) and there is no default value.
-
setLoggerLevel
Attempts to set the desired log level for the specified logger. Note that this may not be permitted by some security managers, in which case the attempt will have no effect.- Parameters:
logger- The logger whose level should be updated.logLevel- The log level to set for the logger.
-
setLogHandlerLevel
Attempts to set the desired log level for the specified log handler. Note that this may not be permitted by some security managers, in which case the attempt will have no effect.- Parameters:
logHandler- The log handler whose level should be updated.logLevel- The log level to set for the log handler.
-
getBytes
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.
-
getBytesForCodePoint
Retrieves a byte array containing the UTF-8 representation of the bytes that comprise the provided Unicode code point.- Parameters:
codePoint- The code point for which to retrieve the UTF-8 bytes.- Returns:
- A byte array containing the UTF-8 representation of the bytes that comprise the provided Unicode code point.
-
isASCIIString
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 benull.- Returns:
trueif the contents of the provided array represent an ASCII string, orfalseif not.
-
isASCIIString
Indicates whether the contents of the provided string 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:
s- The string for which to make the determination. It must not benull.- Returns:
trueif the contents of the provided string represent an ASCII string, orfalseif not.
-
isPrintable
Indicates whether the provided character is a printable ASCII character, as per RFC 4517 section 3.2. The only printable characters are:- All uppercase and lowercase ASCII alphabetic letters
- All ASCII numeric digits
- The following additional ASCII characters: single quote, left parenthesis, right parenthesis, plus, comma, hyphen, period, equals, forward slash, colon, question mark, space.
- Parameters:
c- The character for which to make the determination.- Returns:
trueif the provided character is a printable ASCII character, orfalseif not.
-
isPrintableString
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:- All uppercase and lowercase ASCII alphabetic letters
- All ASCII numeric digits
- The following additional ASCII characters: single quote, left parenthesis, right parenthesis, plus, comma, hyphen, period, equals, forward slash, colon, question mark, space.
- Parameters:
b- The byte array for which to make the determination. It must not benull.- Returns:
trueif the contents of the provided byte array represent a printable LDAP string, orfalseif not.
-
isPrintableString
Indicates whether the provided string represents a printable LDAP string, as per RFC 4517 section 3.2. The only characters allowed in a printable string are:- All uppercase and lowercase ASCII alphabetic letters
- All ASCII numeric digits
- The following additional ASCII characters: single quote, left parenthesis, right parenthesis, plus, comma, hyphen, period, equals, forward slash, colon, question mark, space.
- Parameters:
s- The string for which to make the determination. It must not benull.- Returns:
trueif the provided string represents a printable LDAP string, orfalseif not.
-
isLikelyDisplayableCharacter
Indicates whether the specified Unicode code point represents a character that is believed to be displayable. Displayable characters include letters, numbers, spaces, dashes, punctuation, symbols, and marks. Non-displayable characters include control characters, directionality indicators, like and paragraph separators, format characters, and surrogate characters.- Parameters:
codePoint- The code point for which to make the determination.- Returns:
trueif the specified Unicode character is believed to be displayable, orfalseif not.
-
isLikelyDisplayableUTF8String
Indicates whether the provided byte array represents a valid UTF-8 string that is comprised entirely of characters that are believed to be displayable (as determined by theisLikelyDisplayableCharacter(int)method).- Parameters:
b- The byte array for which to make the determination. It must not benull.- Returns:
trueif the provided byte array represents a valid UTF-8 string that is believed to be displayable, orfalseif not.
-
isLikelyDisplayableString
Indicates whether the provided string is comprised entirely of characters that are believed to be displayable (as determined by theisLikelyDisplayableCharacter(int)method).- Parameters:
s- The string for which to make the determination. It must not benull.- Returns:
trueif the provided string is believed to be displayable, orfalseif not.
-
getCodePoints
Retrieves an array of the code points that comprise the provided string.- Parameters:
s- The string for which to obtain the code points. It must not benull.- Returns:
- An array of the code points that comprise the provided string.
-
isValidUTF8
Indicates whether the contents of the provided array represent a valid UTF-8 string, which may or may not contain non-ASCII characters. Note that this method does not make any attempt to determine whether the characters in the UTF-8 string actually map to assigned Unicode code points.- Parameters:
b- The byte array to examine. It must not benull.- Returns:
trueif the byte array can be parsed as a valid UTF-8 string, orfalseif not.
-
isValidUTF8WithNonASCIICharacters
Indicates whether the contents of the provided array represent a valid UTF-8 string that contains at least one non-ASCII character (and may contain zero or more ASCII characters). Note that this method does not make any attempt to determine whether the characters in the UTF-8 string actually map to assigned Unicode code points.- Parameters:
b- The byte array to examine. It must not benull.- Returns:
trueif the byte array can be parsed as a valid UTF-8 string and contains at least one non-ASCII character, orfalseif not.
-
toUTF8String
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
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.
-
unicodeStringsAreEquivalent
Indicates whether the provided strings represent an equivalent sequence of Unicode characters. In some cases, Unicode supports multiple ways of encoding the same character or sequence of characters, and this method accounts for those alternative encodings in the course of making the determination.- Parameters:
s1- The first string for which to make the determination. It must not benull.s2- The second string for which to make the determination. It must not benull.- Returns:
trueif the provided strings represent an equivalent sequence of Unicode characters, orfalseif not.
-
utf8StringsAreEquivalent
Indicates whether the provided byte arrays represent UTF-8 strings that have an equivalent sequence of Unicode characters. In some cases, Unicode supports multiple ways of encoding the same character or sequence of characters, and this method accounts for those alternative encodings in the course of making the determination.- Parameters:
b1- The bytes that comprise the UTF-8 representation of the first string for which to make the determination. It must not benull.b2- The bytes that comprise the UTF-8 representation of the second string for which to make the determination. It must not benull.- Returns:
trueif the provided byte arrays represent UTF-8 strings that have an equivalent sequence of Unicode characters, orfalseif not.
-
toInitialLowerCase
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. It may be
nullif the provided string isnull.
-
toLowerCase
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, or
nullif the provided string wasnull.
-
toUpperCase
Retrieves an all-uppercase version of the provided string.- Parameters:
s- The string for which to retrieve the uppercase version.- Returns:
- An all-uppercase version of the provided string, or
nullif the provided string wasnull.
-
isHex
Indicates whether the provided character is a valid hexadecimal digit.- Parameters:
c- The character for which to make the determination.- Returns:
trueif the provided character does represent a valid hexadecimal digit, orfalseif not.
-
toHex
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
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
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
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 benull.- Returns:
- A string containing a hexadecimal representation of the contents of the provided byte array.
-
toHex
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 benull.buffer- A buffer to which the hexadecimal representation of the contents of the provided byte array should be appended.
-
toHex
public static void toHex(@NotNull byte[] b, @Nullable String delimiter, @NotNull 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 benull.delimiter- A delimiter to be inserted between bytes. It may benullif 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
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(@Nullable byte[] array, int indent, @NotNull 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.
-
fromHex
Retrieves the bytes that correspond to the provided hexadecimal string.- Parameters:
hexString- The hexadecimal string for which to retrieve the bytes. It must not benull, and there must not be any delimiter between bytes.- Returns:
- The bytes that correspond to the provided hexadecimal string.
- Throws:
ParseException- If the provided string does not represent valid hexadecimal data, or if the provided string does not contain an even number of characters.
-
hexEncode
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.
-
hexEncode
Appends a hex-encoded representation of the provided code point to the given buffer. Each byte of the hex-encoded representation will be prefixed with a backslash.- Parameters:
codePoint- The code point to be encoded.buffer- The buffer to which the hex-encoded representation should be appended.
-
byteArrayToCode
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 benull.buffer- The buffer to which the code should be appended.
-
getBacktrace
Retrieves a single-line string representation of the stack trace for the current thread. It will not include the call to thegetBacktracemethod itself, nor anything that it calls either directly or indirectly.- Returns:
- A single-line string representation of the stack trace for the current thread.
-
getStackTrace
Retrieves a single-line string representation of the stack trace for the providedThrowable. It will include the unqualified name of theThrowableclass, 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- TheThrowablefor which to retrieve the stack trace.- Returns:
- A single-line string representation of the stack trace for the
provided
Throwable.
-
getStackTrace
Appends a single-line string representation of the stack trace for the providedThrowableto the given buffer. It will include the unqualified name of theThrowableclass, 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- TheThrowablefor which to retrieve the stack trace.buffer- The buffer to which the information should be appended.
-
getStackTrace
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(@NotNull StackTraceElement[] elements, @NotNull 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.
-
getStackTrace
public static void getStackTrace(@NotNull StackTraceElement[] elements, @NotNull StringBuilder buffer, int maxPreSDKFrames) 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.maxPreSDKFrames- The maximum number of stack trace frames to include from code invoked before calling into the LDAP SDK. A value of zero indicates that only stack trace frames from the LDAP SDK itself (or things that it calls) will be included. A negative value indicates that
-
getExceptionMessage
Retrieves a string representation of the providedThrowableobject 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 itsgetExceptionMessagemethod 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- TheThrowablefor which to generate the exception message.- Returns:
- A string representation of the provided
Throwableobject suitable for use in a message.
-
getExceptionMessage
@NotNull public static String getExceptionMessage(@Nullable Throwable t, boolean includeCause, boolean includeStackTrace) Retrieves a string representation of the providedThrowableobject 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 itsgetExceptionMessagemethod 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- TheThrowablefor which to generate the exception message.includeCause- Indicates whether to include information about the cause (if any) in the exception message.includeStackTrace- Indicates whether to include a condensed representation of the stack trace in the exception message.- Returns:
- A string representation of the provided
Throwableobject suitable for use in a message.
-
getUnqualifiedClassName
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.
-
getUTCTimeZone
Retrieves aTimeZoneobject that represents the UTC (universal coordinated time) time zone.- Returns:
- A
TimeZoneobject that represents the UTC time zone.
-
encodeGeneralizedTime
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 theSystem.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
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
Decodes the provided string as a timestamp in generalized time format.- Parameters:
t- The timestamp to be decoded. It must not benull.- Returns:
- The
Dateobject decoded from the provided timestamp. - Throws:
ParseException- If the provided string could not be decoded as a timestamp in generalized time format.
-
encodeRFC3339Time
Encodes the provided timestamp to the ISO 8601 format described in RFC 3339.- Parameters:
timestamp- The timestamp to be encoded in the RFC 3339 format. It should use the same format as theSystem.currentTimeMillis()method (i.e., the number of milliseconds since 12:00am UTC on January 1, 1970).- Returns:
- The RFC 3339 representation of the provided date.
-
encodeRFC3339Time
Encodes the provided timestamp to the ISO 8601 format described in RFC 3339.- Parameters:
d- The date to be encoded in the RFC 3339 format.- Returns:
- The RFC 3339 representation of the provided date.
-
decodeRFC3339Time
Decodes the provided string as a timestamp encoded in the ISO 8601 format described in RFC 3339.- Parameters:
timestamp- The timestamp to be decoded in the RFC 3339 format.- Returns:
- The
Dateobject decoded from the provided timestamp. - Throws:
ParseException- If the provided string could not be decoded as a timestamp in the RFC 3339 time format.
-
trimLeading
Trims only leading spaces from the provided string, leaving any trailing spaces intact.- Parameters:
s- The string to be processed. It must not benull.- 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
Trims only trailing spaces from the provided string, leaving any leading spaces intact.- Parameters:
s- The string to be processed. It must not benull.- 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
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 benull.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
@NotNull public static List<String> wrapLine(@NotNull 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 benull.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 unlessmaxFirstLineWidthis less than or equal to zero.- Returns:
- A list of the wrapped lines. It may be empty if the provided line contained only spaces.
-
cleanExampleCommandLineArgument
This method returns a form of the provided argument that is safe to use on the command line for the local platform. This method is provided as a convenience wrapper aroundExampleCommandLineArgument. Calling this method is equivalent to:return ExampleCommandLineArgument.getCleanArgument(s).getLocalForm();
For getting direct access to command line arguments that are safe to use on other platforms, callExampleCommandLineArgument.getCleanArgument(java.lang.String).- Parameters:
s- The string to be processed. It must not benull.- Returns:
- A cleaned version of the provided string in a form that will allow it to be displayed as the value of a command-line argument on.
-
concatenateStrings
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 benullbut may be empty.- Returns:
- A string containing a concatenation of all of the strings in the provided array.
-
concatenateStrings
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 benullbut may be empty.- Returns:
- A string containing a concatenation of all of the strings in the provided list.
-
concatenateStrings
@NotNull public static String concatenateStrings(@Nullable String beforeList, @Nullable String beforeElement, @Nullable String betweenElements, @Nullable String afterElement, @Nullable String afterList, @NotNull 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 benullor 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 benullor empty if nothing should be placed before each element.betweenElements- The separator that should be placed between elements in the list. It may benullor empty if no separator should be placed between elements.afterElement- A string that should be placed after each element in the list. It may benullor empty if nothing should be placed after each element.afterList- A string that should be placed at the end of the list. It may benullor empty if nothing should be placed at the end of the list.a- The array of strings to concatenate. It must not benullbut may be empty.- Returns:
- A string containing a concatenation of all of the strings in the provided list.
-
concatenateStrings
@NotNull public static String concatenateStrings(@Nullable String beforeList, @Nullable String beforeElement, @Nullable String betweenElements, @Nullable String afterElement, @Nullable String afterList, @NotNull List<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 benullor 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 benullor empty if nothing should be placed before each element.betweenElements- The separator that should be placed between elements in the list. It may benullor empty if no separator should be placed between elements.afterElement- A string that should be placed after each element in the list. It may benullor empty if nothing should be placed after each element.afterList- A string that should be placed at the end of the list. It may benullor empty if nothing should be placed at the end of the list.l- The list of strings to concatenate. It must not benullbut may be empty.- Returns:
- A string containing a concatenation of all of the strings in the provided list.
-
secondsToHumanReadableDuration
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
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
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
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
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 benull.- Returns:
trueif the provided string is a valid numeric OID, orfalseif not.
-
capitalize
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, or
nullif the provided string wasnull.
-
capitalize
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, or
nullif the provided string wasnull.
-
encodeUUID
Encodes the provided UUID to a byte array containing its 128-bit representation.- Parameters:
uuid- The UUID to be encoded. It must not benull.- Returns:
- The byte array containing the 128-bit encoded UUID.
-
decodeUUID
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 benull.- Returns:
- The decoded UUID.
- Throws:
ParseException- If the provided byte array cannot be parsed as a UUID.
-
isWindows
Returnstrueif and only if the current process is running on a Windows-based operating system.- Returns:
trueif the current process is running on a Windows-based operating system andfalseotherwise.
-
getCommandLineContinuationString
Retrieves the string that should be appended to the end of all but the last line of a multi-line command to indicate that the command continues onto the next line.
This will be the caret (also called a circumflex accent) character on Windows systems, and a backslash (also called a reverse solidus) character on Linux and UNIX-based systems.
The string value that is returned will not include a space, but it should generally be preceded by one or more space to separate it from the previous component on the command line.- Returns:
- The string that should be appended (generally after one or more spaces to separate it from the previous component) to the end of all but the last line of a multi-line command to indicate that the command continues onto the next line.
-
toArgumentList
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:
ParseException- If a problem is encountered while attempting to parse the given string to an argument list.
-
toArray
Retrieves an array containing the elements of the provided collection.- Type Parameters:
T- The type of element included in the provided collection.- Parameters:
collection- The collection to convert to an array.type- The type of element contained in the collection.- Returns:
- An array containing the elements of the provided list, or
nullif the provided list isnull.
-
toList
Creates a modifiable list with all of the items of the provided array in the same order. This method behaves much likeArrays.asList, except that if the provided array isnull, then it will return anulllist 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
nullif the provided array wasnull.
-
toNonNullList
Creates a modifiable list with all of the items of the provided array in the same order. This method behaves much likeArrays.asList, except that if the provided array isnull, 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
Indicates whether both of the provided objects arenullor both are logically equal (using theequalsmethod).- Parameters:
o1- The first object for which to make the determination.o2- The second object for which to make the determination.- Returns:
trueif both objects arenullor both are logically equal, orfalseif only one of the objects isnullor they are not logically equal.
-
bothNullOrEqualIgnoreCase
Indicates whether both of the provided strings arenullor both are logically equal ignoring differences in capitalization (using theequalsIgnoreCasemethod).- Parameters:
s1- The first string for which to make the determination.s2- The second string for which to make the determination.- Returns:
trueif both strings arenullor both are logically equal ignoring differences in capitalization, orfalseif only one of the objects isnullor they are not logically equal ignoring capitalization.
-
stringsEqualIgnoreCaseOrderIndependent
public static boolean stringsEqualIgnoreCaseOrderIndependent(@Nullable String[] a1, @Nullable 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 containsnullstrings, 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:
trueif both arrays have the same set of strings, orfalseif not.
-
arraysEqualOrderIndependent
Indicates whether the provided arrays have the same elements, ignoring the order in which they appear. It is assumed that neither array containsnullelements, 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:
trueif both arrays have the same set of elements, orfalseif not.
-
numBytesInUTF8CharacterWithFirstByte
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
Indicates whether the provided attribute name should be considered a sensitive attribute for the purposes oftoCodemethods. If an attribute is considered sensitive, then its values will be redacted in the output of thetoCodemethods.- Parameters:
name- The name for which to make the determination. It may or may not include attribute options. It must not benull.- Returns:
trueif the specified attribute is one that should be considered sensitive for the
-
getSensitiveToCodeAttributeBaseNames
Retrieves a set containing the base names (in all lowercase characters) of any attributes that should be considered sensitive for the purposes of thetoCodemethods. 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
toCodemethods.
-
setSensitiveToCodeAttributes
Specifies the names of any attributes that should be considered sensitive for the purposes of thetoCodemethods.- Parameters:
names- The names of any attributes that should be considered sensitive for the purposes of thetoCodemethods. It may benullor empty if no attributes should be considered sensitive.
-
setSensitiveToCodeAttributes
Specifies the names of any attributes that should be considered sensitive for the purposes of thetoCodemethods.- Parameters:
names- The names of any attributes that should be considered sensitive for the purposes of thetoCodemethods. It may benullor empty if no attributes should be considered sensitive.
-
createIOExceptionWithCause
@NotNull public static IOException createIOExceptionWithCause(@Nullable String message, @Nullable Throwable cause) Creates a newIOExceptionwith 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 benullif the message should be generated from the provided cause.cause- The underlying cause for the exception. It may benullif the exception should have only a message.- Returns:
- The
IOExceptionobject that was created.
-
stringToLines
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.
-
linesToString
Creates a string that is a concatenation of all of the provided lines, with a line break (using the end-of-line sequence appropriate for the underlying platform) after each line (including the last line).- Parameters:
lines- The lines to include in the string.- Returns:
- The string resulting from concatenating the provided lines with line breaks.
-
linesToString
Creates a string that is a concatenation of all of the provided lines, with a line break (using the end-of-line sequence appropriate for the underlying platform) after each line (including the last line).- Parameters:
lines- The lines to include in the string.- Returns:
- The string resulting from concatenating the provided lines with line breaks.
-
constructPath
@NotNull public static File constructPath(@NotNull File baseDirectory, @Nullable String... pathElements) Constructs aFileobject from the provided path.- Parameters:
baseDirectory- The base directory to use as the starting point. It must not benulland is expected to represent a directory.pathElements- An array of the elements that make up the remainder of the path to the specified file, in order from paths closest to the root of the filesystem to furthest away (that is, the first element should represent a file or directory immediately below the base directory, the second is one level below that, and so on). It may benullor empty if the base directory should be used.- Returns:
- The constructed
Fileobject.
-
byteArray
Creates a byte array from the provided integer values. All of the integer values must be between 0x00 and 0xFF (0 and 255), inclusive. Any bits set outside of that range will be ignored.- Parameters:
bytes- The values to include in the byte array.- Returns:
- A byte array with the provided set of values.
-
isWithinUnitTest
Indicates whether the unit tests are currently running in this JVM.- Returns:
trueif the unit tests are currently running, orfalseif not.
-
throwErrorOrRuntimeException
public static void throwErrorOrRuntimeException(@NotNull Throwable throwable) throws Error, RuntimeException Throws anErroror aRuntimeExceptionbased on the providedThrowableobject. This method will always throw something, regardless of the providedThrowableobject.- Parameters:
throwable- TheThrowableobject to use to create the exception to throw.- Throws:
Error- If the providedThrowableobject is anErrorinstance, then thatErrorinstance will be re-thrown.RuntimeException- If the providedThrowableobject is aRuntimeExceptioninstance, then thatRuntimeExceptioninstance will be re-thrown. Otherwise, it must be a checked exception and that checked exception will be re-thrown as aRuntimeException.
-
rethrowIfErrorOrRuntimeException
public static void rethrowIfErrorOrRuntimeException(@NotNull Throwable throwable) throws Error, RuntimeException Re-throws the providedThrowableinstance only if it is anErroror aRuntimeExceptioninstance; otherwise, this method will return without taking any action.- Parameters:
throwable- TheThrowableobject to examine and potentially re-throw.- Throws:
Error- If the providedThrowableobject is anErrorinstance, then thatErrorinstance will be re-thrown.RuntimeException- If the providedThrowableobject is aRuntimeExceptioninstance, then thatRuntimeExceptioninstance will be re-thrown.
-
rethrowIfError
Re-throws the providedThrowableinstance only if it is anError; otherwise, this method will return without taking any action.- Parameters:
throwable- TheThrowableobject to examine and potentially re-throw.- Throws:
Error- If the providedThrowableobject is anErrorinstance, then thatErrorinstance will be re-thrown.
-
computeMapCapacity
Computes the capacity that should be used for a map or a set with the expected number of elements, which can help avoid the need to re-hash or re-balance the map if too many items are added. This method bases its computation on the default map load factor of 0.75.- Parameters:
expectedItemCount- The expected maximum number of items that will be placed in the map or set. It must be greater than or equal to zero.- Returns:
- The capacity that should be used for a map or a set with the expected number of elements
-
setOf
Creates an unmodifiable set containing the provided items. The iteration order of the provided items will be preserved.- Type Parameters:
T- The type of item to include in the set.- Parameters:
items- The items to include in the set. It must not benull, but may be empty.- Returns:
- An unmodifiable set containing the provided items.
-
hashSetOf
Creates aHashSetcontaining the provided items.- Type Parameters:
T- The type of item to include in the set.- Parameters:
items- The items to include in the set. It must not benull, but may be empty.- Returns:
- A
HashSetcontaining the provided items.
-
linkedHashSetOf
Creates aLinkedHashSetcontaining the provided items.- Type Parameters:
T- The type of item to include in the set.- Parameters:
items- The items to include in the set. It must not benull, but may be empty.- Returns:
- A
LinkedHashSetcontaining the provided items.
-
treeSetOf
Creates aTreeSetcontaining the provided items.- Type Parameters:
T- The type of item to include in the set.- Parameters:
items- The items to include in the set. It must not benull, but may be empty.- Returns:
- A
LinkedHashSetcontaining the provided items.
-
mapOf
Creates an unmodifiable map containing the provided items.- Type Parameters:
K- The type for the map keys.V- The type for the map values.- Parameters:
key- The only key to include in the map.value- The only value to include in the map.- Returns:
- The unmodifiable map that was created.
-
mapOf
@NotNull public static <K,V> Map<K,V> mapOf(@NotNull K key1, @NotNull V value1, @NotNull K key2, @NotNull V value2) Creates an unmodifiable map containing the provided items.- Type Parameters:
K- The type for the map keys.V- The type for the map values.- Parameters:
key1- The first key to include in the map.value1- The first value to include in the map.key2- The second key to include in the map.value2- The second value to include in the map.- Returns:
- The unmodifiable map that was created.
-
mapOf
@NotNull public static <K,V> Map<K,V> mapOf(@NotNull K key1, @NotNull V value1, @NotNull K key2, @NotNull V value2, @NotNull K key3, @NotNull V value3) Creates an unmodifiable map containing the provided items.- Type Parameters:
K- The type for the map keys.V- The type for the map values.- Parameters:
key1- The first key to include in the map.value1- The first value to include in the map.key2- The second key to include in the map.value2- The second value to include in the map.key3- The third key to include in the map.value3- The third value to include in the map.- Returns:
- The unmodifiable map that was created.
-
mapOf
@NotNull public static <K,V> Map<K,V> mapOf(@NotNull K key1, @NotNull V value1, @NotNull K key2, @NotNull V value2, @NotNull K key3, @NotNull V value3, @NotNull K key4, @NotNull V value4) Creates an unmodifiable map containing the provided items.- Type Parameters:
K- The type for the map keys.V- The type for the map values.- Parameters:
key1- The first key to include in the map.value1- The first value to include in the map.key2- The second key to include in the map.value2- The second value to include in the map.key3- The third key to include in the map.value3- The third value to include in the map.key4- The fourth key to include in the map.value4- The fourth value to include in the map.- Returns:
- The unmodifiable map that was created.
-
mapOf
@NotNull public static <K,V> Map<K,V> mapOf(@NotNull K key1, @NotNull V value1, @NotNull K key2, @NotNull V value2, @NotNull K key3, @NotNull V value3, @NotNull K key4, @NotNull V value4, @NotNull K key5, @NotNull V value5) Creates an unmodifiable map containing the provided items.- Type Parameters:
K- The type for the map keys.V- The type for the map values.- Parameters:
key1- The first key to include in the map.value1- The first value to include in the map.key2- The second key to include in the map.value2- The second value to include in the map.key3- The third key to include in the map.value3- The third value to include in the map.key4- The fourth key to include in the map.value4- The fourth value to include in the map.key5- The fifth key to include in the map.value5- The fifth value to include in the map.- Returns:
- The unmodifiable map that was created.
-
mapOf
@NotNull public static <K,V> Map<K,V> mapOf(@NotNull K key1, @NotNull V value1, @NotNull K key2, @NotNull V value2, @NotNull K key3, @NotNull V value3, @NotNull K key4, @NotNull V value4, @NotNull K key5, @NotNull V value5, @NotNull K key6, @NotNull V value6) Creates an unmodifiable map containing the provided items.- Type Parameters:
K- The type for the map keys.V- The type for the map values.- Parameters:
key1- The first key to include in the map.value1- The first value to include in the map.key2- The second key to include in the map.value2- The second value to include in the map.key3- The third key to include in the map.value3- The third value to include in the map.key4- The fourth key to include in the map.value4- The fourth value to include in the map.key5- The fifth key to include in the map.value5- The fifth value to include in the map.key6- The sixth key to include in the map.value6- The sixth value to include in the map.- Returns:
- The unmodifiable map that was created.
-
mapOf
@NotNull public static <K,V> Map<K,V> mapOf(@NotNull K key1, @NotNull V value1, @NotNull K key2, @NotNull V value2, @NotNull K key3, @NotNull V value3, @NotNull K key4, @NotNull V value4, @NotNull K key5, @NotNull V value5, @NotNull K key6, @NotNull V value6, @NotNull K key7, @NotNull V value7) Creates an unmodifiable map containing the provided items.- Type Parameters:
K- The type for the map keys.V- The type for the map values.- Parameters:
key1- The first key to include in the map.value1- The first value to include in the map.key2- The second key to include in the map.value2- The second value to include in the map.key3- The third key to include in the map.value3- The third value to include in the map.key4- The fourth key to include in the map.value4- The fourth value to include in the map.key5- The fifth key to include in the map.value5- The fifth value to include in the map.key6- The sixth key to include in the map.value6- The sixth value to include in the map.key7- The seventh key to include in the map.value7- The seventh value to include in the map.- Returns:
- The unmodifiable map that was created.
-
mapOf
@NotNull public static <K,V> Map<K,V> mapOf(@NotNull K key1, @NotNull V value1, @NotNull K key2, @NotNull V value2, @NotNull K key3, @NotNull V value3, @NotNull K key4, @NotNull V value4, @NotNull K key5, @NotNull V value5, @NotNull K key6, @NotNull V value6, @NotNull K key7, @NotNull V value7, @NotNull K key8, @NotNull V value8) Creates an unmodifiable map containing the provided items.- Type Parameters:
K- The type for the map keys.V- The type for the map values.- Parameters:
key1- The first key to include in the map.value1- The first value to include in the map.key2- The second key to include in the map.value2- The second value to include in the map.key3- The third key to include in the map.value3- The third value to include in the map.key4- The fourth key to include in the map.value4- The fourth value to include in the map.key5- The fifth key to include in the map.value5- The fifth value to include in the map.key6- The sixth key to include in the map.value6- The sixth value to include in the map.key7- The seventh key to include in the map.value7- The seventh value to include in the map.key8- The eighth key to include in the map.value8- The eighth value to include in the map.- Returns:
- The unmodifiable map that was created.
-
mapOf
@NotNull public static <K,V> Map<K,V> mapOf(@NotNull K key1, @NotNull V value1, @NotNull K key2, @NotNull V value2, @NotNull K key3, @NotNull V value3, @NotNull K key4, @NotNull V value4, @NotNull K key5, @NotNull V value5, @NotNull K key6, @NotNull V value6, @NotNull K key7, @NotNull V value7, @NotNull K key8, @NotNull V value8, @NotNull K key9, @NotNull V value9) Creates an unmodifiable map containing the provided items.- Type Parameters:
K- The type for the map keys.V- The type for the map values.- Parameters:
key1- The first key to include in the map.value1- The first value to include in the map.key2- The second key to include in the map.value2- The second value to include in the map.key3- The third key to include in the map.value3- The third value to include in the map.key4- The fourth key to include in the map.value4- The fourth value to include in the map.key5- The fifth key to include in the map.value5- The fifth value to include in the map.key6- The sixth key to include in the map.value6- The sixth value to include in the map.key7- The seventh key to include in the map.value7- The seventh value to include in the map.key8- The eighth key to include in the map.value8- The eighth value to include in the map.key9- The ninth key to include in the map.value9- The ninth value to include in the map.- Returns:
- The unmodifiable map that was created.
-
mapOf
@NotNull public static <K,V> Map<K,V> mapOf(@NotNull K key1, @NotNull V value1, @NotNull K key2, @NotNull V value2, @NotNull K key3, @NotNull V value3, @NotNull K key4, @NotNull V value4, @NotNull K key5, @NotNull V value5, @NotNull K key6, @NotNull V value6, @NotNull K key7, @NotNull V value7, @NotNull K key8, @NotNull V value8, @NotNull K key9, @NotNull V value9, @NotNull K key10, @NotNull V value10) Creates an unmodifiable map containing the provided items.- Type Parameters:
K- The type for the map keys.V- The type for the map values.- Parameters:
key1- The first key to include in the map.value1- The first value to include in the map.key2- The second key to include in the map.value2- The second value to include in the map.key3- The third key to include in the map.value3- The third value to include in the map.key4- The fourth key to include in the map.value4- The fourth value to include in the map.key5- The fifth key to include in the map.value5- The fifth value to include in the map.key6- The sixth key to include in the map.value6- The sixth value to include in the map.key7- The seventh key to include in the map.value7- The seventh value to include in the map.key8- The eighth key to include in the map.value8- The eighth value to include in the map.key9- The ninth key to include in the map.value9- The ninth value to include in the map.key10- The tenth key to include in the map.value10- The tenth value to include in the map.- Returns:
- The unmodifiable map that was created.
-
mapOf
Creates an unmodifiable map containing the provided items. The map entries must have the same data type for keys and values.- Type Parameters:
T- The type for the map keys and values.- Parameters:
items- The items to include in the map. If it is null or empty, the map will be empty. If it is non-empty, then the number of elements in the array must be a multiple of two. Elements in even-numbered indexes will be the keys for the map entries, while elements in odd-numbered indexes will be the map values.- Returns:
- The unmodifiable map that was created.
-
mapOfObjectPairs
@SafeVarargs @NotNull public static <K,V> Map<K,V> mapOfObjectPairs(@Nullable ObjectPair<K, V>... items) Creates an unmodifiable map containing the provided items.- Type Parameters:
K- The type for the map keys.V- The type for the map values.- Parameters:
items- The items to include in the map.- Returns:
- The unmodifiable map that was created.
-
getAllLocalAddresses
Attempts to determine all addresses associated with the local system, including loopback addresses.- Parameters:
nameResolver- The name resolver to use to determine the local host and loopback addresses. If this isnull, then the LDAP SDK's default name resolver will be used.- Returns:
- A set of the local addresses that were identified.
-
getAllLocalAddresses
@NotNull public static Set<InetAddress> getAllLocalAddresses(@Nullable NameResolver nameResolver, boolean includeLoopback) Attempts to determine all addresses associated with the local system, optionally including loopback addresses.- Parameters:
nameResolver- The name resolver to use to determine the local host and loopback addresses. If this isnull, then the LDAP SDK's default name resolver will be used.includeLoopback- Indicates whether to include loopback addresses in the set that is returned.- Returns:
- A set of the local addresses that were identified.
-
getCanonicalHostNameIfAvailable
@Nullable public static String getCanonicalHostNameIfAvailable(@Nullable NameResolver nameResolver, @NotNull InetAddress address) Retrieves the canonical host name for the provided address, if it can be resolved to a name.- Parameters:
nameResolver- The name resolver to use to obtain the canonical host name. If this isnull, then the LDAP SDK's default name resolver will be used.address- TheInetAddressfor which to attempt to obtain the canonical host name.- Returns:
- The canonical host name for the provided address, or
nullif it cannot be obtained (either because the attempt returnsnull, which shouldn't happen, or because it matches the IP address).
-
getAvailableCanonicalHostNames
@NotNull public static Set<String> getAvailableCanonicalHostNames(@Nullable NameResolver nameResolver, @NotNull Collection<InetAddress> addresses) Retrieves the canonical host names for the provided set ofInetAddressobjects. If any of the provided addresses cannot be resolved to a canonical host name (in which case the attempt to get the canonical host name will return its IP address), it will be excluded from the returned set.- Parameters:
nameResolver- The name resolver to use to obtain the canonical host names. If this isnull, then the LDAP SDK's default name resolver will be used.addresses- The set of addresses for which to obtain the canonical host names.- Returns:
- A set of the canonical host names that could be obtained from the provided addresses.
-
trimInterfaceNameFromHostAddress
Retrieves a version of the provided host address with the interface name stripped off. Java sometimes follows an IP address with a percent sign and the interface name. If that interface name is present in the provided host address, then this method will trim it off, leaving just the IP address. If the provided host address does not include the interface name, then the provided address will be returned as-is.- Parameters:
hostAddress- The host address to be trimmed.- Returns:
- The provided host address without the interface name.
-
isIANAReservedIPAddress
public static boolean isIANAReservedIPAddress(@NotNull InetAddress address, boolean includePrivateUseNetworkAddresses) Indicates whether the provided address is marked as reserved in the IANA IPv4 address space registry at https://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.txt or the IPv6 address space registry at https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.txt.- Parameters:
address- The address for which to make the determination. It must not benull, and it must be an IPv4 or IPv6 address.includePrivateUseNetworkAddresses- Indicates whether to consider addresses in a private-use network address range (including 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, and fc00::/7) as reserved addresses. If this istrue, then this method will returntruefor addresses in a private-use network range; if it isfalse, then this method will returnfalsefor addresses in those ranges. This does not have any effect for addresses in other reserved address ranges.- Returns:
trueif the provided address is in a reserved address range, orfalseif not.
-
isIANAReservedIPv4Address
public static boolean isIANAReservedIPv4Address(@NotNull Inet4Address address, boolean includePrivateUseNetworkAddresses) Indicates whether the provided address is marked as reserved in the IANA IPv4 address space registry at https://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.txt. This implementation is based on the version of the registry that was updated on 2019-12-27.- Parameters:
address- The IPv4 address for which to make the determination. It must not benull, and it must be an IPv4 address.includePrivateUseNetworkAddresses- Indicates whether to consider addresses in a private-use network address range as reserved addresses.- Returns:
trueif the provided address is in a reserved address range, orfalseif not.
-
isIANAReservedIPv6Address
public static boolean isIANAReservedIPv6Address(@NotNull Inet6Address address, boolean includePrivateUseNetworkAddresses) Indicates whether the provided address is marked as reserved in the IANA IPv6 address space registry at https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.txt. This implementation is based on the version of the registry that was updated on 2019-09-13.- Parameters:
address- The IPv4 address for which to make the determination. It must not benull, and it must be an IPv6 address.includePrivateUseNetworkAddresses- Indicates whether to consider addresses in a private-use network address range as reserved addresses.- Returns:
trueif the provided address is in a reserved address range, orfalseif not.
-
readFileBytes
Reads the bytes that comprise the specified file.- Parameters:
path- The path to the file to be read.- Returns:
- The bytes that comprise the specified file.
- Throws:
IOException- If a problem occurs while trying to read the file.
-
readFileBytes
Reads the bytes that comprise the specified file.- Parameters:
file- The file to be read.- Returns:
- The bytes that comprise the specified file.
- Throws:
IOException- If a problem occurs while trying to read the file.
-
readFileAsString
@NotNull public static String readFileAsString(@NotNull String path, boolean includeFinalLineBreak) throws IOException Reads the contents of the specified file as a string. All line breaks in the file will be preserved, with the possible exception of the one on the last line.- Parameters:
path- The path to the file to be read.includeFinalLineBreak- Indicates whether the final line break (if there is one) should be preserved.- Returns:
- The contents of the specified file as a string.
- Throws:
IOException- If a problem occurs while trying to read the file.
-
readFileAsString
@NotNull public static String readFileAsString(@NotNull File file, boolean includeFinalLineBreak) throws IOException Reads the contents of the specified file as a string. All line breaks in the file will be preserved, with the possible exception of the one on the last line.- Parameters:
file- The file to be read.includeFinalLineBreak- Indicates whether the final line break (if there is one) should be preserved.- Returns:
- The contents of the specified file as a string.
- Throws:
IOException- If a problem occurs while trying to read the file.
-
readFileLines
Reads the lines that comprise the specified file.- Parameters:
path- The path to the file to be read.- Returns:
- The lines that comprise the specified file.
- Throws:
IOException- If a problem occurs while trying to read the file.
-
readFileLines
Reads the lines that comprise the specified file.- Parameters:
file- The file to be read.- Returns:
- The lines that comprise the specified file.
- Throws:
IOException- If a problem occurs while trying to read the file.
-
writeFile
Writes the provided bytes to the specified file. If the file already exists, it will be overwritten.- Parameters:
path- The path to the file to be written.bytes- The bytes to be written to the specified file.- Throws:
IOException- If a problem is encountered while writing the file.
-
writeFile
Writes the provided bytes to the specified file. If the file already exists, it will be overwritten.- Parameters:
file- The file to be written.bytes- The bytes to be written to the specified file.- Throws:
IOException- If a problem is encountered while writing the file.
-
writeFile
public static void writeFile(@NotNull String path, @NotNull CharSequence... lines) throws IOException Writes the provided lines to the specified file, with each followed by an appropriate end-of-line marker for the current platform. If the file already exists, it will be overwritten.- Parameters:
path- The path to the file to be written.lines- The lines to be written to the specified file.- Throws:
IOException- If a problem is encountered while writing the file.
-
writeFile
Writes the provided lines to the specified file, with each followed by an appropriate end-of-line marker for the current platform. If the file already exists, it will be overwritten.- Parameters:
file- The file to be written.lines- The lines to be written to the specified file.- Throws:
IOException- If a problem is encountered while writing the file.
-
writeFile
public static void writeFile(@NotNull String path, @Nullable List<? extends CharSequence> lines) throws IOException Writes the provided lines to the specified file, with each followed by an appropriate end-of-line marker for the current platform. If the file already exists, it will be overwritten.- Parameters:
path- The path to the file to be written.lines- The lines to be written to the specified file.- Throws:
IOException- If a problem is encountered while writing the file.
-
writeFile
public static void writeFile(@NotNull File file, @Nullable List<? extends CharSequence> lines) throws IOException Writes the provided lines to the specified file, with each followed by an appropriate end-of-line marker for the current platform. If the file already exists, it will be overwritten.- Parameters:
file- The file to be written.lines- The lines to be written to the specified file.- Throws:
IOException- If a problem is encountered while writing the file.
-
randomBytes
Retrieves a byte array with the specified number of randomly selected bytes.- Parameters:
numBytes- The number of bytes of random data to retrieve. It must be greater than or equal to zero.secure- Indicates whether to use a cryptographically secure random number generator.- Returns:
- A byte array with the specified number of randomly selected bytes.
-
randomInt
Retrieves a randomly selected integer between the given upper and lower bounds.- Parameters:
lowerBound- The lowest value that may be selected at random. It must be less than or equal to the upper bound.upperBound- The highest value that may be selected at random. It must be greater than or equal to the lower bound.secure- Indicates whether to use a cryptographically secure random number generator.- Returns:
- A randomly selected integer between the given upper and lower bounds.
-
randomAlphabeticString
Retrieves a string containing the specified number of randomly selected ASCII letters. It will contain only lowercase letters.- Parameters:
length- The number of letters to include in the string. It must be greater than or equal to zero.secure- Indicates whether to use a cryptographically secure random number generator.- Returns:
- The randomly generated alphabetic string.
-
randomNumericString
Retrieves a string containing the specified number of randomly selected ASCII numeric digits.- Parameters:
length- The number of digits to include in the string. It must be greater than or equal to zero.secure- Indicates whether to use a cryptographically secure random number generator.- Returns:
- The randomly generated numeric string.
-
randomAlphanumericString
Retrieves a string containing the specified number of randomly selected ASCII alphanumeric characters. It may contain a mix of lowercase letters, uppercase letters, and numeric digits.- Parameters:
length- The number of characters to include in the string. It must be greater than or equal to zero.secure- Indicates whether to use a cryptographically secure random number generator.- Returns:
- The randomly generated alphanumeric string.
-
randomString
@NotNull public static String randomString(int length, @NotNull char[] allowedChars, boolean secure) Retrieves a string containing the specified number of randomly selected characters from the given set.- Parameters:
length- The number of characters to include in the string. It must be greater than or equal to zero.allowedChars- The set of characters that are allowed to be included in the string. It must not benullor empty.secure- Indicates whether to use a cryptographically secure random number generator.- Returns:
- The randomly generated string.
-