Class Strings
- java.lang.Object
-
- org.apache.directory.api.util.Strings
-
public final class Strings extends Object
Various string manipulation methods that are more efficient then chaining string operations: all is done in the same buffer without creating a bunch of string objects.- Author:
- Apache Directory Project
-
-
Field Summary
Fields Modifier and Type Field Description static byte[]
EMPTY_BYTES
An empty byte arraystatic String
EMPTY_STRING
An empty Stringstatic String[]
EMPTY_STRING_ARRAY
An empty String arraystatic byte[]
HEX_CHAR
Hex chars
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static int
areEquals(byte[] bytes, int index, byte[] bytes2)
Check if a text is present at the current position in a buffer.static int
areEquals(byte[] bytes, int index, String text)
Check if a text is present at the current position in a buffer.static int
areEquals(char[] chars, int index, char[] chars2)
Check if a text is present at the current position in a buffer.static int
areEquals(char[] chars, int index, char[] chars2, boolean caseSensitive)
Check if a text is present at the current position in a buffer.static int
areEquals(char[] chars, int index, String text)
Check if a text is present at the current position in a buffer.static int
areEquals(char[] chars, int index, String text, boolean caseSensitive)
Check if a text is present at the current position in a buffer.static boolean
areEquals(String string, int index, String text)
Check if a text is present at the current position in another string.static String
asciiBytesToString(byte[] bytes)
Transform an array of ASCII bytes to a string. the byte array should contains only values in [0, 127].static byte
byteAt(byte[] bytes, int index)
Get the byte at a given position in a byte array, checking for limitsstatic String
byteToString(byte b)
Helper function that dump a byte as a double digit valuestatic String
centerTrunc(String str, int head, int tail)
Truncates large Strings showing a portion of the String's head and tail with the center cut out and replaced with '...'.static char
charAt(char[] chars, int index)
Get the char at a given position in a byte array, checking for limitsstatic char
charAt(String string, int index)
Get the character at a given position in a string, checking for limitsstatic int
compare(byte[] b1, byte[] b2)
static byte[]
copy(byte[] value)
Copy a byte array into a new byte arraystatic String
deepTrim(String string)
A deep trim of a string remove whitespace from the ends as well as excessive whitespace within the inside of the string between non-whitespace characters.static String
deepTrim(String str, boolean toLowerCase)
Put common code to deepTrim(String) and deepTrimToLower here.static String
deepTrimToLower(String string)
This does the same thing as a trim but we also lowercase the string while performing the deep trim within the same buffer.static String
dumpByte(byte octet)
Helper function that dump a byte in hex formstatic String
dumpBytes(byte[] buffer)
Helper function that dump an array of bytes in hex formstatic char
dumpHex(byte hex)
Helper function that returns a char from an hexstatic String
dumpHexPairs(byte[] buffer)
Helper function that dump an array of bytes in hex pair form, without '0x' and space charsstatic boolean
equals(String str1, String str2)
Compares two Strings, returningtrue
if they are equal.static String
formatHtml(String source, boolean replaceNl, boolean replaceTag, boolean replaceQuote)
This method is used to insert HTML block dynamicallystatic byte[]
getBytesUtf8(String string)
Return UTF-8 encoded byte[] representation of a Stringstatic byte[]
getBytesUtf8Ascii(String string)
When the string to convert to bytes is pure ascii, this is a faster method than the getBytesUtf8.static String
getDefaultCharsetName()
Get the default charsetstatic String
getString(byte[] data, int offset, int length, String charset)
From commons-httpclients.static String
getString(byte[] data, int offset, int length, Charset charset)
From commons-httpclients.static String
getString(byte[] data, String charset)
From commons-httpclients.static String
getString(byte[] data, Charset charset)
From commons-httpclients.static String
getUUID(long value)
Create a new UUID using a long as the least significant bitsstatic boolean
isCharASCII(byte[] byteArray, int index, char car)
Test if the current character is equal to a specific character.static boolean
isCharASCII(char[] charArray, int index, char car)
Test if the current character is equal to a specific character.static boolean
isCharASCII(String string, int index, char car)
Test if the current character is equal to a specific character.static boolean
isEmpty(byte[] bytes)
Checks if a bytes array is empty or null.static boolean
isEmpty(String str)
Checks if a String is empty ("") or null.static boolean
isIA5String(String str)
Check that a String is a valid IA5String.static boolean
isNotEmpty(String str)
Checks if a String is not empty ("") and not null.static boolean
isPrintableString(String str)
Check that a String is a valid PrintableString.static boolean
isValidUuid(String uuid)
Checks to see if a String is a valid UUID.static String
listToString(List<?> list)
Utility method that return a String representation of a liststatic String
listToString(List<?> list, String tabs)
Utility method that return a String representation of a liststatic String
lowerCase(String str)
Converts a String to lower case as perString.toLowerCase()
.static String
lowerCaseAscii(String str)
Rewrote the toLowercase method to improve performances.static String
mapToString(Map<?,?> map)
Utility method that return a String representation of a map.static String
mapToString(Map<?,?> map, String tabs)
Utility method that return a String representation of a map.static int
parseInt(String value)
Past an ASCII String to a numberstatic String
setToString(Set<?> set)
Utility method that return a String representation of a setstatic byte[]
toByteArray(String hexString)
Get byte array from hex stringstatic String
toHexString(byte[] res)
Gets a hex string from byte array.static String
toLowerCase(byte[] value)
Rewrote the toLowercase method to improve performances.static String
toLowerCase(String value)
Deprecated.static String
toLowerCaseAscii(String value)
Rewrote the toLowercase method to improve performances.static String
toUpperCase(String value)
Deprecated.static String
toUpperCaseAscii(String value)
Rewrote the toLowercase method to improve performances.static byte[]
trim(byte[] bytes)
Removes spaces (char <= 32) from both start and ends of this bytes array, handlingnull
by returningnull
.static String
trim(String str)
Removes spaces (char <= 32) from both start and ends of this String, handlingnull
by returningnull
.static String
trimConsecutiveToOne(String str, char ch)
Trims several consecutive characters into one.static int
trimLeft(byte[] bytes, int pos)
Removes spaces (char <= 32) from start of this array, handlingnull
by returningnull
.static void
trimLeft(byte[] bytes, Position pos)
Removes spaces (char <= 32) from a position in this array, handlingnull
by returningnull
.static int
trimLeft(char[] chars, int pos)
Removes spaces (char <= 32) from start of this array, handlingnull
by returningnull
.static String
trimLeft(String str)
Removes spaces (char <= 32) from start of this String, handlingnull
by returningnull
.static void
trimLeft(String string, Position pos)
Removes spaces (char <= 32) from a position in this array, handlingnull
by returningnull
.static int
trimRight(byte[] bytes, int pos)
Removes spaces (char <= 32) from end of this array, handlingnull
by returningnull
.static String
trimRight(byte[] bytes, Position pos)
Removes spaces (char <= 32) from end of this string, handlingnull
by returningnull
.static int
trimRight(char[] chars, int pos)
Removes spaces (char <= 32) from end of this array, handlingnull
by returningnull
.static String
trimRight(String str)
Removes spaces (char <= 32) from end of this String, handlingnull
by returningnull
.static String
trimRight(String str, int escapedSpace)
Removes spaces (char <= 32) from end of this String, handlingnull
by returningnull
.static String
trimRight(String string, Position pos)
Removes spaces (char <= 32) from end of this string, handlingnull
by returningnull
.static String
upperCase(String str)
Converts a String to upper case as perString.toUpperCase( Locale )
.static String
utf8ToString(byte[] bytes)
Return an UTF-8 encoded Stringstatic String
utf8ToString(byte[] bytes, int length)
Return an UTF-8 encoded Stringstatic String
utf8ToString(byte[] bytes, int start, int length)
Return an UTF-8 encoded Stringstatic byte[]
uuidToBytes(String string)
converts the string representation of an UUID to bytesstatic String
uuidToString(byte[] bytes)
converts the bytes of a UUID to string
-
-
-
Field Detail
-
HEX_CHAR
public static final byte[] HEX_CHAR
Hex chars
-
EMPTY_BYTES
public static final byte[] EMPTY_BYTES
An empty byte array
-
EMPTY_STRING
public static final String EMPTY_STRING
An empty String- See Also:
- Constant Field Values
-
EMPTY_STRING_ARRAY
public static final String[] EMPTY_STRING_ARRAY
An empty String array
-
-
Method Detail
-
dumpBytes
public static String dumpBytes(byte[] buffer)
Helper function that dump an array of bytes in hex form- Parameters:
buffer
- The bytes array to dump- Returns:
- A string representation of the array of bytes
-
byteToString
public static String byteToString(byte b)
Helper function that dump a byte as a double digit value- Parameters:
b
- The byte to dump- Returns:
- A string representation of byte as a string
-
dumpByte
public static String dumpByte(byte octet)
Helper function that dump a byte in hex form- Parameters:
octet
- The byte to dump- Returns:
- A string representation of the byte
-
dumpHex
public static char dumpHex(byte hex)
Helper function that returns a char from an hex- Parameters:
hex
- The hex to dump- Returns:
- A char representation of the hex
-
dumpHexPairs
public static String dumpHexPairs(byte[] buffer)
Helper function that dump an array of bytes in hex pair form, without '0x' and space chars- Parameters:
buffer
- The bytes array to dump- Returns:
- A string representation of the array of bytes
-
deepTrim
public static String deepTrim(String str, boolean toLowerCase)
Put common code to deepTrim(String) and deepTrimToLower here.- Parameters:
str
- the string to deep trimtoLowerCase
- how to normalize for case: upper or lower- Returns:
- the deep trimmed string
- See Also:
deepTrim( String )
-
deepTrimToLower
public static String deepTrimToLower(String string)
This does the same thing as a trim but we also lowercase the string while performing the deep trim within the same buffer. This saves us from having to create multiple String and StringBuilder objects and is much more efficient.- Parameters:
string
- The String to modify- Returns:
- The modified String
- See Also:
deepTrim( String )
-
deepTrim
public static String deepTrim(String string)
A deep trim of a string remove whitespace from the ends as well as excessive whitespace within the inside of the string between non-whitespace characters. A deep trim reduces internal whitespace down to a single space to preserve the whitespace separated tokenization order of the String.- Parameters:
string
- the string to deep trim.- Returns:
- the trimmed string.
-
trimConsecutiveToOne
public static String trimConsecutiveToOne(String str, char ch)
Trims several consecutive characters into one.- Parameters:
str
- the string to trim consecutive characters ofch
- the character to trim down- Returns:
- the newly trimmed down string
-
centerTrunc
public static String centerTrunc(String str, int head, int tail)
Truncates large Strings showing a portion of the String's head and tail with the center cut out and replaced with '...'. Also displays the total length of the truncated string so size of '...' can be interpreted. Useful for large strings in UIs or hex dumps to log files.- Parameters:
str
- the string to truncatehead
- the amount of the head to displaytail
- the amount of the tail to display- Returns:
- the center truncated string
-
toHexString
public static String toHexString(byte[] res)
Gets a hex string from byte array.- Parameters:
res
- the byte array- Returns:
- the hex string representing the binary values in the array
-
toByteArray
public static byte[] toByteArray(String hexString)
Get byte array from hex string- Parameters:
hexString
- the hex string to convert to a byte array- Returns:
- the byte form of the hex string.
-
formatHtml
public static String formatHtml(String source, boolean replaceNl, boolean replaceTag, boolean replaceQuote)
This method is used to insert HTML block dynamically- Parameters:
source
- the HTML code to be processesreplaceNl
- if true '\n' will be replaced by <br>replaceTag
- if true '<' will be replaced by < and '>' will be replaced by >replaceQuote
- if true '\"' will be replaced by "- Returns:
- the formated html block
-
areEquals
public static boolean areEquals(String string, int index, String text)
Check if a text is present at the current position in another string.- Parameters:
string
- The string which contains the dataindex
- Current position in the stringtext
- The text we want to check- Returns:
true
if the string contains the text.
-
isCharASCII
public static boolean isCharASCII(byte[] byteArray, int index, char car)
Test if the current character is equal to a specific character. This function works only for character between 0 and 127, as it does compare a byte and a char (which is 16 bits wide)- Parameters:
byteArray
- The buffer which contains the dataindex
- Current position in the buffercar
- The character we want to compare with the current buffer position- Returns:
true
if the current character equals the given character.
-
isCharASCII
public static boolean isCharASCII(char[] charArray, int index, char car)
Test if the current character is equal to a specific character. This function works only for character between 0 and 127, as it does compare a byte and a char (which is 16 bits wide)- Parameters:
charArray
- The buffer which contains the dataindex
- Current position in the buffercar
- The character we want to compare with the current buffer position- Returns:
true
if the current character equals the given character.
-
isCharASCII
public static boolean isCharASCII(String string, int index, char car)
Test if the current character is equal to a specific character.- Parameters:
string
- The String which contains the dataindex
- Current position in the stringcar
- The character we want to compare with the current string position- Returns:
true
if the current character equals the given character.
-
utf8ToString
public static String utf8ToString(byte[] bytes)
Return an UTF-8 encoded String- Parameters:
bytes
- The byte array to be transformed to a String- Returns:
- A String.
-
utf8ToString
public static String utf8ToString(byte[] bytes, int length)
Return an UTF-8 encoded String- Parameters:
bytes
- The byte array to be transformed to a Stringlength
- The length of the byte array to be converted- Returns:
- A String.
-
utf8ToString
public static String utf8ToString(byte[] bytes, int start, int length)
Return an UTF-8 encoded String- Parameters:
bytes
- The byte array to be transformed to a Stringstart
- the starting position in the byte arraylength
- The length of the byte array to be converted- Returns:
- A String.
-
areEquals
public static int areEquals(byte[] bytes, int index, String text)
Check if a text is present at the current position in a buffer.- Parameters:
bytes
- The buffer which contains the dataindex
- Current position in the buffertext
- The text we want to check- Returns:
true
if the buffer contains the text.
-
areEquals
public static int areEquals(char[] chars, int index, String text)
Check if a text is present at the current position in a buffer.- Parameters:
chars
- The buffer which contains the dataindex
- Current position in the buffertext
- The text we want to check- Returns:
true
if the buffer contains the text.
-
areEquals
public static int areEquals(char[] chars, int index, String text, boolean caseSensitive)
Check if a text is present at the current position in a buffer.- Parameters:
chars
- The buffer which contains the dataindex
- Current position in the buffertext
- The text we want to checkcaseSensitive
- If the comparison is case-sensitive- Returns:
true
if the buffer contains the text.
-
areEquals
public static int areEquals(char[] chars, int index, char[] chars2)
Check if a text is present at the current position in a buffer.- Parameters:
chars
- The buffer which contains the dataindex
- Current position in the bufferchars2
- The text we want to check- Returns:
true
if the buffer contains the text.
-
areEquals
public static int areEquals(char[] chars, int index, char[] chars2, boolean caseSensitive)
Check if a text is present at the current position in a buffer.- Parameters:
chars
- The buffer which contains the dataindex
- Current position in the bufferchars2
- The text we want to checkcaseSensitive
- If the comparison is case-sensitive- Returns:
true
if the buffer contains the text.
-
areEquals
public static int areEquals(byte[] bytes, int index, byte[] bytes2)
Check if a text is present at the current position in a buffer.- Parameters:
bytes
- The buffer which contains the dataindex
- Current position in the bufferbytes2
- The text we want to check- Returns:
true
if the buffer contains the text.
-
isEmpty
public static boolean isEmpty(String str)
Checks if a String is empty ("") or null.
StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0. It no longer trims the String. That functionality is available in isBlank().
- Parameters:
str
- the String to check, may be null- Returns:
true
if the String is empty or null
-
isEmpty
public static boolean isEmpty(byte[] bytes)
Checks if a bytes array is empty or null.- Parameters:
bytes
- The bytes array to check, may be null- Returns:
true
if the bytes array is empty or null
-
trim
public static String trim(String str)
Removes spaces (char <= 32) from both start and ends of this String, handling
Trim removes start and end characters <= 32.null
by returningnull
.StringUtils.trim(null) = null StringUtils.trim("") = "" StringUtils.trim(" ") = "" StringUtils.trim("abc") = "abc" StringUtils.trim(" abc ") = "abc"
- Parameters:
str
- the String to be trimmed, may be null- Returns:
- the trimmed string,
null
if null String input
-
trim
public static byte[] trim(byte[] bytes)
Removes spaces (char <= 32) from both start and ends of this bytes array, handling
Trim removes start and end characters <= 32.null
by returningnull
.StringUtils.trim(null) = null StringUtils.trim("") = "" StringUtils.trim(" ") = "" StringUtils.trim("abc") = "abc" StringUtils.trim(" abc ") = "abc"
- Parameters:
bytes
- the byte array to be trimmed, may be null- Returns:
- the trimmed byte array
-
trimLeft
public static String trimLeft(String str)
Removes spaces (char <= 32) from start of this String, handling
Trim removes start characters <= 32.null
by returningnull
.StringUtils.trimLeft(null) = null StringUtils.trimLeft("") = "" StringUtils.trimLeft(" ") = "" StringUtils.trimLeft("abc") = "abc" StringUtils.trimLeft(" abc ") = "abc "
- Parameters:
str
- the String to be trimmed, may be null- Returns:
- the trimmed string,
null
if null String input
-
trimLeft
public static int trimLeft(char[] chars, int pos)
Removes spaces (char <= 32) from start of this array, handling
Trim removes start characters <= 32.null
by returningnull
.StringUtils.trimLeft(null) = null StringUtils.trimLeft("") = "" StringUtils.trimLeft(" ") = "" StringUtils.trimLeft("abc") = "abc" StringUtils.trimLeft(" abc ") = "abc "
- Parameters:
chars
- the chars array to be trimmed, may be nullpos
- The position in the char[]- Returns:
- the position of the first char which is not a space, or the last position of the array.
-
trimLeft
public static void trimLeft(String string, Position pos)
Removes spaces (char <= 32) from a position in this array, handling
Trim removes start characters <= 32.null
by returningnull
.StringUtils.trimLeft(null) = null StringUtils.trimLeft("",...) = "" StringUtils.trimLeft(" ",...) = "" StringUtils.trimLeft("abc",...) = "abc" StringUtils.trimLeft(" abc ",...) = "abc "
- Parameters:
string
- the string to be trimmed, may be nullpos
- The position in the String
-
trimLeft
public static void trimLeft(byte[] bytes, Position pos)
Removes spaces (char <= 32) from a position in this array, handling
Trim removes start characters <= 32.null
by returningnull
.StringUtils.trimLeft(null) = null StringUtils.trimLeft("",...) = "" StringUtils.trimLeft(" ",...) = "" StringUtils.trimLeft("abc",...) = "abc" StringUtils.trimLeft(" abc ",...) = "abc "
- Parameters:
bytes
- the byte array to be trimmed, may be nullpos
- The position in the byte[]
-
trimLeft
public static int trimLeft(byte[] bytes, int pos)
Removes spaces (char <= 32) from start of this array, handling
Trim removes start characters <= 32.null
by returningnull
.StringUtils.trimLeft(null) = null StringUtils.trimLeft("") = "" StringUtils.trimLeft(" ") = "" StringUtils.trimLeft("abc") = "abc" StringUtils.trimLeft(" abc ") = "abc "
- Parameters:
bytes
- the byte array to be trimmed, may be nullpos
- The position in the byte[]- Returns:
- the position of the first byte which is not a space, or the last position of the array.
-
trimRight
public static String trimRight(String str)
Removes spaces (char <= 32) from end of this String, handling
Trim removes start characters <= 32.null
by returningnull
.StringUtils.trimRight(null) = null StringUtils.trimRight("") = "" StringUtils.trimRight(" ") = "" StringUtils.trimRight("abc") = "abc" StringUtils.trimRight(" abc ") = " abc"
- Parameters:
str
- the String to be trimmed, may be null- Returns:
- the trimmed string,
null
if null String input
-
trimRight
public static String trimRight(String str, int escapedSpace)
Removes spaces (char <= 32) from end of this String, handling
Trim removes start characters <= 32.null
by returningnull
.StringUtils.trimRight(null) = null StringUtils.trimRight("") = "" StringUtils.trimRight(" ") = "" StringUtils.trimRight("abc") = "abc" StringUtils.trimRight(" abc ") = " abc"
- Parameters:
str
- the String to be trimmed, may be nullescapedSpace
- The last escaped space, if any- Returns:
- the trimmed string,
null
if null String input
-
trimRight
public static int trimRight(char[] chars, int pos)
Removes spaces (char <= 32) from end of this array, handling
Trim removes start characters <= 32.null
by returningnull
.StringUtils.trimRight(null) = null StringUtils.trimRight("") = "" StringUtils.trimRight(" ") = "" StringUtils.trimRight("abc") = "abc" StringUtils.trimRight(" abc ") = " abc"
- Parameters:
chars
- the chars array to be trimmed, may be nullpos
- The position in the char[]- Returns:
- the position of the first char which is not a space, or the last position of the array.
-
trimRight
public static String trimRight(String string, Position pos)
Removes spaces (char <= 32) from end of this string, handling
Trim removes start characters <= 32.null
by returningnull
.StringUtils.trimRight(null) = null StringUtils.trimRight("") = "" StringUtils.trimRight(" ") = "" StringUtils.trimRight("abc") = "abc" StringUtils.trimRight(" abc ") = " abc"
- Parameters:
string
- the string to be trimmed, may be nullpos
- The position in the String- Returns:
- the position of the first char which is not a space, or the last position of the string.
-
trimRight
public static String trimRight(byte[] bytes, Position pos)
Removes spaces (char <= 32) from end of this string, handling
Trim removes start characters <= 32.null
by returningnull
.StringUtils.trimRight(null) = null StringUtils.trimRight("") = "" StringUtils.trimRight(" ") = "" StringUtils.trimRight("abc") = "abc" StringUtils.trimRight(" abc ") = " abc"
- Parameters:
bytes
- the byte array to be trimmed, may be nullpos
- The position in the byte[]- Returns:
- the position of the first char which is not a space, or the last position of the byte array.
-
trimRight
public static int trimRight(byte[] bytes, int pos)
Removes spaces (char <= 32) from end of this array, handling
Trim removes start characters <= 32.null
by returningnull
.StringUtils.trimRight(null) = null StringUtils.trimRight("") = "" StringUtils.trimRight(" ") = "" StringUtils.trimRight("abc") = "abc" StringUtils.trimRight(" abc ") = " abc"
- Parameters:
bytes
- the byte array to be trimmed, may be nullpos
- The position in the byte[]- Returns:
- the position of the first char which is not a space, or the last position of the array.
-
charAt
public static char charAt(String string, int index)
Get the character at a given position in a string, checking for limits- Parameters:
string
- The string which contains the dataindex
- Current position in the string- Returns:
- The character at the given position, or '\0' if something went wrong
-
byteAt
public static byte byteAt(byte[] bytes, int index)
Get the byte at a given position in a byte array, checking for limits- Parameters:
bytes
- The byte[] which contains the dataindex
- Current position in the byte[]- Returns:
- The byte at the given position, or '\0' if something went wrong
-
charAt
public static char charAt(char[] chars, int index)
Get the char at a given position in a byte array, checking for limits- Parameters:
chars
- The char[] which contains the dataindex
- Current position in the char[]- Returns:
- The byte at the given position, or '\0' if something went wrong
-
asciiBytesToString
public static String asciiBytesToString(byte[] bytes)
Transform an array of ASCII bytes to a string. the byte array should contains only values in [0, 127].- Parameters:
bytes
- The byte array to transform- Returns:
- The resulting string
-
getBytesUtf8
public static byte[] getBytesUtf8(String string)
Return UTF-8 encoded byte[] representation of a String- Parameters:
string
- The string to be transformed to a byte array- Returns:
- The transformed byte array
-
getBytesUtf8Ascii
public static byte[] getBytesUtf8Ascii(String string)
When the string to convert to bytes is pure ascii, this is a faster method than the getBytesUtf8. Otherwise, it's slower.- Parameters:
string
- The string to convert to byte[]- Returns:
- The bytes
-
getDefaultCharsetName
public static String getDefaultCharsetName()
Get the default charset- Returns:
- The default charset
-
equals
public static boolean equals(String str1, String str2)
Compares two Strings, returning
true
if they are equal.null
s are handled without exceptions. Twonull
references are considered to be equal. The comparison is case sensitive.StringUtils.equals(null, null) = true StringUtils.equals(null, "abc") = false StringUtils.equals("abc", null) = false StringUtils.equals("abc", "abc") = true StringUtils.equals("abc", "ABC") = false
- Parameters:
str1
- the first String, may be nullstr2
- the second String, may be null- Returns:
true
if the Strings are equal, case sensitive, or bothnull
- See Also:
String.equals(Object)
-
listToString
public static String listToString(List<?> list)
Utility method that return a String representation of a list- Parameters:
list
- The list to transform to a string- Returns:
- A csv string
-
setToString
public static String setToString(Set<?> set)
Utility method that return a String representation of a set- Parameters:
set
- The set to transform to a string- Returns:
- A csv string
-
listToString
public static String listToString(List<?> list, String tabs)
Utility method that return a String representation of a list- Parameters:
list
- The list to transform to a stringtabs
- The tabs to add in front of the elements- Returns:
- A csv string
-
mapToString
public static String mapToString(Map<?,?> map)
Utility method that return a String representation of a map. The elements will be represented as "key = value"- Parameters:
map
- The map to transform to a string- Returns:
- A csv string
-
mapToString
public static String mapToString(Map<?,?> map, String tabs)
Utility method that return a String representation of a map. The elements will be represented as "key = value"- Parameters:
map
- The map to transform to a stringtabs
- The tabs to add in ffront of the elements- Returns:
- A csv string
-
toLowerCase
@Deprecated public static String toLowerCase(String value)
Deprecated.Rewrote the toLowercase method to improve performances. In Ldap, attributesType are supposed to use ASCII chars : 'a'-'z', 'A'-'Z', '0'-'9', '.' and '-' only.
Deprecated : UsetoLowerCaseAscii(String)
- Parameters:
value
- The String to lowercase- Returns:
- The lowercase string
-
toLowerCaseAscii
public static String toLowerCaseAscii(String value)
Rewrote the toLowercase method to improve performances. In Ldap, attributesType are supposed to use ASCII chars : 'a'-'z', 'A'-'Z', '0'-'9', '.' and '-' only.- Parameters:
value
- The String to lowercase- Returns:
- The lowercase string
-
toLowerCase
public static String toLowerCase(byte[] value)
Rewrote the toLowercase method to improve performances. In Ldap, attributesType are supposed to use ASCII chars : 'a'-'z', 'A'-'Z', '0'-'9', '.' and '-' only.- Parameters:
value
- The byte[] to lowercase- Returns:
- The lowercase string
-
toUpperCase
@Deprecated public static String toUpperCase(String value)
Deprecated.Rewrote the toUppercase method to improve performances. In Ldap, attributesType are supposed to use ASCII chars : 'a'-'z', 'A'-'Z', '0'-'9', '.' and '-' only. We also add the '_' char
Deprecated UsetoUpperCaseAscii(String)
- Parameters:
value
- The String to uppercase- Returns:
- The uppercase string
-
toUpperCaseAscii
public static String toUpperCaseAscii(String value)
Rewrote the toLowercase method to improve performances. In Ldap, attributesType are supposed to use ASCII chars : 'a'-'z', 'A'-'Z', '0'-'9', '.' and '-' only.- Parameters:
value
- The String to uppercase- Returns:
- The uppercase string
-
upperCase
public static String upperCase(String str)
Converts a String to upper case as per
String.toUpperCase( Locale )
.A
null
input String returnsnull
.StringUtils.upperCase(null) = null StringUtils.upperCase("") = "" StringUtils.upperCase("aBc") = "ABC"
- Parameters:
str
- the String to upper case, may be null- Returns:
- the upper cased String,
null
if null String input
-
lowerCase
public static String lowerCase(String str)
Converts a String to lower case as per
String.toLowerCase()
.A
null
input String returnsnull
.StringUtils.lowerCase(null) = null StringUtils.lowerCase("") = "" StringUtils.lowerCase("aBc") = "abc"
- Parameters:
str
- the String to lower case, may be null- Returns:
- the lower cased String,
null
if null String input
-
lowerCaseAscii
public static String lowerCaseAscii(String str)
Rewrote the toLowercase method to improve performances. In Ldap, attributesType are supposed to use ASCII chars : 'a'-'z', 'A'-'Z', '0'-'9', '.' and '-' only. We will take care of any other chars either.- Parameters:
str
- The String to lowercase- Returns:
- The lowercase string
-
isPrintableString
public static boolean isPrintableString(String str)
Check that a String is a valid PrintableString. A PrintableString contains only the following set of chars : { ' ', ''', '(', ')', '+', '-', '.', '/', [0-9], ':', '=', '?', [A-Z], [a-z]}- Parameters:
str
- The String to check- Returns:
true
if the string is a PrintableString or is empty,false
otherwise
-
isNotEmpty
public static boolean isNotEmpty(String str)
Checks if a String is not empty ("") and not null.
StringUtils.isNotEmpty(null) = false StringUtils.isNotEmpty("") = false StringUtils.isNotEmpty(" ") = true StringUtils.isNotEmpty("bob") = true StringUtils.isNotEmpty(" bob ") = true
- Parameters:
str
- the String to check, may be null- Returns:
true
if the String is not empty and not null
-
isIA5String
public static boolean isIA5String(String str)
Check that a String is a valid IA5String. An IA5String contains only char which values is between [0, 7F]- Parameters:
str
- The String to check- Returns:
true
if the string is an IA5String or is empty,false
otherwise
-
isValidUuid
public static boolean isValidUuid(String uuid)
Checks to see if a String is a valid UUID.- Parameters:
uuid
- the UUID to check for validity- Returns:
- true if the UUID is valid, false otherwise
-
uuidToString
public static String uuidToString(byte[] bytes)
converts the bytes of a UUID to string- Parameters:
bytes
- bytes of a UUID- Returns:
- UUID in string format
-
uuidToBytes
public static byte[] uuidToBytes(String string)
converts the string representation of an UUID to bytes- Parameters:
string
- the string representation of an UUID- Returns:
- the bytes, null if the the syntax is not valid
-
copy
public static byte[] copy(byte[] value)
Copy a byte array into a new byte array- Parameters:
value
- the byte array to copy- Returns:
- The copied byte array
-
getString
public static String getString(byte[] data, int offset, int length, String charset)
From commons-httpclients. Converts the byte array of HTTP content characters to a string. If the specified charset is not supported, default system encoding is used.- Parameters:
data
- the byte array to be encodedoffset
- the index of the first byte to encodelength
- the number of bytes to encodecharset
- the desired character encoding- Returns:
- The result of the conversion.
- Since:
- 3.0
-
getString
public static String getString(byte[] data, int offset, int length, Charset charset)
From commons-httpclients. Converts the byte array of HTTP content characters to a string. If the specified charset is not supported, default system encoding is used.- Parameters:
data
- the byte array to be encodedoffset
- the index of the first byte to encodelength
- the number of bytes to encodecharset
- the desired character encoding- Returns:
- The result of the conversion.
- Since:
- 3.0
-
getString
public static String getString(byte[] data, String charset)
From commons-httpclients. Converts the byte array of HTTP content characters to a string. If the specified charset is not supported, default system encoding is used.- Parameters:
data
- the byte array to be encodedcharset
- the desired character encoding- Returns:
- The result of the conversion.
- Since:
- 3.0
-
getString
public static String getString(byte[] data, Charset charset)
From commons-httpclients. Converts the byte array of HTTP content characters to a string. If the specified charset is not supported, default system encoding is used.- Parameters:
data
- the byte array to be encodedcharset
- the desired character encoding- Returns:
- The result of the conversion.
- Since:
- 3.0
-
getUUID
public static String getUUID(long value)
Create a new UUID using a long as the least significant bits- Parameters:
value
- The least significant bits.- Returns:
- The created UUID
-
parseInt
public static int parseInt(String value)
Past an ASCII String to a number- Parameters:
value
- The string to parse- Returns:
- the parsed value.
-
compare
public static int compare(byte[] b1, byte[] b2)
- Parameters:
b1
- The first byte[] to compareb2
- The second byte[] to compare- Returns:
- -1 if the first byte[] is inferior to the second one, 1 if teh first byte[] is superior to the second one, 0 if they are equal.
- See Also:
Comparator.compare(java.lang.Object, java.lang.Object)
-
-