|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.directory.api.util.Strings
public final class Strings
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.
| Field Summary | |
|---|---|
static byte[] |
EMPTY_BYTES
A empty byte array |
static boolean[] |
IS_PRINTABLE_CHAR
A table containing booleans when the corresponding char is printable |
static char[] |
TO_LOWER_CASE
|
static char[] |
UPPER_CASE
upperCase = 'A' .. |
| Method Summary | |
|---|---|
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,
String text)
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)
Thansform an array of ASCII bytes to a string. |
static byte |
byteAt(byte[] bytes,
int index)
Get the byte at a given position in a byte array, checking for limits |
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 '...'. |
static char |
charAt(String string,
int index)
Get the character at a given position in a string, checking for limits |
static byte[] |
copy(byte[] value)
Copy a byte array into a new byte array |
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. |
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 form |
static String |
dumpBytes(byte[] buffer)
Helper function that dump an array of bytes in hex form |
static char |
dumpHex(byte hex)
Helper function that returns a char from an hex |
static String |
dumpHexPairs(byte[] buffer)
Helper function that dump an array of bytes in hex pair form, without '0x' and space chars |
static boolean |
equals(String str1,
String str2)
Compares two Strings, returning true if they are equal. |
static String |
formatHtml(String source,
boolean replaceNl,
boolean replaceTag,
boolean replaceQuote)
This method is used to insert HTML block dynamically |
static byte[] |
getBytesUtf8(String string)
Return UTF-8 encoded byte[] representation of a String |
static byte[] |
getBytesUtf8Ascii(String string)
When the string to convert to bytes is pure ascii, ths is a faster method than the getBytesUtf8. |
static String |
getDefaultCharsetName()
Get the default charset |
static String |
getString(byte[] data,
int offset,
int length,
String charset)
From commons-httpclients. |
static String |
getString(byte[] data,
String charset)
From commons-httpclients. |
static String |
getUUID(long value)
Create a new UUID using a long as the least significant bits |
static boolean |
isCharASCII(byte[] byteArray,
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 list |
static String |
listToString(List<?> list,
String tabs)
Utility method that return a String representation of a list |
static String |
lowerCase(String str)
Converts a String to lower case as per String.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 String |
setToString(Set<?> set)
Utility method that return a String representation of a set |
static byte[] |
toByteArray(String hexString)
Get byte array from hex string |
static String |
toHexString(byte[] res)
Gets a hex string from byte array. |
static String |
toLowerCase(String value)
Rewrote the toLowercase method to improve performances. |
static String |
toUpperCase(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, handling null by returning null. |
static String |
trim(String str)
Removes spaces (char <= 32) from both start and ends of this String, handling null by returning null. |
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, handling null by returning null. |
static void |
trimLeft(byte[] bytes,
Position pos)
Removes spaces (char <= 32) from a position in this array, handling null by returning null. |
static int |
trimLeft(char[] chars,
int pos)
Removes spaces (char <= 32) from start of this array, handling null by returning null. |
static String |
trimLeft(String str)
Removes spaces (char <= 32) from start of this String, handling null by returning null. |
static void |
trimLeft(String string,
Position pos)
Removes spaces (char <= 32) from a position in this array, handling null by returning null. |
static int |
trimRight(byte[] bytes,
int pos)
Removes spaces (char <= 32) from end of this array, handling null by returning null. |
static String |
trimRight(byte[] bytes,
Position pos)
Removes spaces (char <= 32) from end of this string, handling null by returning null. |
static int |
trimRight(char[] chars,
int pos)
Removes spaces (char <= 32) from end of this array, handling null by returning null. |
static String |
trimRight(String str)
Removes spaces (char <= 32) from end of this String, handling null by returning null. |
static String |
trimRight(String str,
int escapedSpace)
Removes spaces (char <= 32) from end of this String, handling null by returning null. |
static String |
trimRight(String string,
Position pos)
Removes spaces (char <= 32) from end of this string, handling null by returning null. |
static String |
upperCase(String str)
Converts a String to upper case as per String.toUpperCase(). |
static String |
utf8ToString(byte[] bytes)
Return an UTF-8 encoded String |
static String |
utf8ToString(byte[] bytes,
int length)
Return an UTF-8 encoded String |
static String |
utf8ToString(byte[] bytes,
int start,
int length)
Return an UTF-8 encoded String |
static byte[] |
uuidToBytes(String string)
converts the string representation of an UUID to bytes |
static String |
uuidToString(byte[] bytes)
converts the bytes of a UUID to string |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final boolean[] IS_PRINTABLE_CHAR
public static final char[] TO_LOWER_CASE
public static final char[] UPPER_CASE
public static final byte[] EMPTY_BYTES
| Method Detail |
|---|
public static String dumpBytes(byte[] buffer)
buffer - The bytes array to dump
public static String dumpByte(byte octet)
octet - The byte to dump
public static char dumpHex(byte hex)
hex - The hex to dump
public static String dumpHexPairs(byte[] buffer)
buffer - The bytes array to dump
public static String deepTrim(String str,
boolean toLowerCase)
str - the string to deep trimtoLowerCase - how to normalize for case: upper or lower
TODO Replace the toCharArray() by substring manipulationspublic static String deepTrimToLower(String string)
deepTrim( String )public static String deepTrim(String string)
string - the string to deep trim.
public static String trimConsecutiveToOne(String str,
char ch)
str - the string to trim consecutive characters ofch - the character to trim down
public static String centerTrunc(String str,
int head,
int tail)
str - the string to truncatehead - the amount of the head to displaytail - the amount of the tail to display
public static String toHexString(byte[] res)
res - the byte array
public static byte[] toByteArray(String hexString)
hexString - the hex string to convert to a byte array
public static String formatHtml(String source,
boolean replaceNl,
boolean replaceTag,
boolean replaceQuote)
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 "
public static boolean areEquals(String string,
int index,
String text)
string - The string which contains the dataindex - Current position in the stringtext - The text we want to check
true if the string contains the text.
public static boolean isCharASCII(byte[] byteArray,
int index,
char car)
byteArray - The buffer which contains the dataindex - Current position in the buffercar - The character we want to compare with the current buffer position
true if the current character equals the given character.
public static boolean isCharASCII(String string,
int index,
char car)
string - The String which contains the dataindex - Current position in the stringcar - The character we want to compare with the current string position
true if the current character equals the given character.public static String utf8ToString(byte[] bytes)
bytes - The byte array to be transformed to a String
public static String utf8ToString(byte[] bytes,
int length)
bytes - The byte array to be transformed to a Stringlength - The length of the byte array to be converted
public static String utf8ToString(byte[] bytes,
int start,
int length)
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
public static int areEquals(byte[] bytes,
int index,
String text)
bytes - The buffer which contains the dataindex - Current position in the buffertext - The text we want to check
true if the buffer contains the text.
public static int areEquals(char[] chars,
int index,
String text)
chars - The buffer which contains the dataindex - Current position in the buffertext - The text we want to check
true if the buffer contains the text.
public static int areEquals(char[] chars,
int index,
char[] chars2)
chars - The buffer which contains the dataindex - Current position in the bufferchars2 - The text we want to check
true if the buffer contains the text.
public static int areEquals(byte[] bytes,
int index,
byte[] bytes2)
bytes - The buffer which contains the dataindex - Current position in the bufferbytes2 - The text we want to check
true if the buffer contains the text.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().
str - the String to check, may be null
true if the String is empty or nullpublic static boolean isEmpty(byte[] bytes)
bytes - The bytes array to check, may be null
true if the bytes array is empty or nullpublic static String trim(String str)
Removes spaces (char <= 32) from both start and ends of this String,
handling null by returning null.
StringUtils.trim(null) = null
StringUtils.trim("") = ""
StringUtils.trim(" ") = ""
StringUtils.trim("abc") = "abc"
StringUtils.trim(" abc ") = "abc"
str - the String to be trimmed, may be null
null if null String inputpublic static byte[] trim(byte[] bytes)
Removes spaces (char <= 32) from both start and ends of this bytes
array, handling null by returning null.
StringUtils.trim(null) = null
StringUtils.trim("") = ""
StringUtils.trim(" ") = ""
StringUtils.trim("abc") = "abc"
StringUtils.trim(" abc ") = "abc"
bytes - the byte array to be trimmed, may be null
public static String trimLeft(String str)
Removes spaces (char <= 32) from start of this String, handling
null by returning null.
StringUtils.trimLeft(null) = null
StringUtils.trimLeft("") = ""
StringUtils.trimLeft(" ") = ""
StringUtils.trimLeft("abc") = "abc"
StringUtils.trimLeft(" abc ") = "abc "
str - the String to be trimmed, may be null
null if null String input
public static int trimLeft(char[] chars,
int pos)
Removes spaces (char <= 32) from start of this array, handling
null by returning null.
StringUtils.trimLeft(null) = null
StringUtils.trimLeft("") = ""
StringUtils.trimLeft(" ") = ""
StringUtils.trimLeft("abc") = "abc"
StringUtils.trimLeft(" abc ") = "abc "
chars - the chars array to be trimmed, may be null
public static void trimLeft(String string,
Position pos)
Removes spaces (char <= 32) from a position in this array, handling
null by returning null.
StringUtils.trimLeft(null) = null
StringUtils.trimLeft("",...) = ""
StringUtils.trimLeft(" ",...) = ""
StringUtils.trimLeft("abc",...) = "abc"
StringUtils.trimLeft(" abc ",...) = "abc "
string - the string to be trimmed, may be nullpos - The starting position
public static void trimLeft(byte[] bytes,
Position pos)
Removes spaces (char <= 32) from a position in this array, handling
null by returning null.
StringUtils.trimLeft(null) = null
StringUtils.trimLeft("",...) = ""
StringUtils.trimLeft(" ",...) = ""
StringUtils.trimLeft("abc",...) = "abc"
StringUtils.trimLeft(" abc ",...) = "abc "
bytes - the byte array to be trimmed, may be nullpos - The starting position
public static int trimLeft(byte[] bytes,
int pos)
Removes spaces (char <= 32) from start of this array, handling
null by returning null.
StringUtils.trimLeft(null) = null
StringUtils.trimLeft("") = ""
StringUtils.trimLeft(" ") = ""
StringUtils.trimLeft("abc") = "abc"
StringUtils.trimLeft(" abc ") = "abc "
bytes - the byte array to be trimmed, may be null
public static String trimRight(String str)
Removes spaces (char <= 32) from end of this String, handling
null by returning null.
StringUtils.trimRight(null) = null
StringUtils.trimRight("") = ""
StringUtils.trimRight(" ") = ""
StringUtils.trimRight("abc") = "abc"
StringUtils.trimRight(" abc ") = " abc"
str - the String to be trimmed, may be null
null if null String input
public static String trimRight(String str,
int escapedSpace)
Removes spaces (char <= 32) from end of this String, handling
null by returning null.
StringUtils.trimRight(null) = null
StringUtils.trimRight("") = ""
StringUtils.trimRight(" ") = ""
StringUtils.trimRight("abc") = "abc"
StringUtils.trimRight(" abc ") = " abc"
str - the String to be trimmed, may be nullescapedSpace - The last escaped space, if any
null if null String input
public static int trimRight(char[] chars,
int pos)
Removes spaces (char <= 32) from end of this array, handling
null by returning null.
StringUtils.trimRight(null) = null
StringUtils.trimRight("") = ""
StringUtils.trimRight(" ") = ""
StringUtils.trimRight("abc") = "abc"
StringUtils.trimRight(" abc ") = " abc"
chars - the chars array to be trimmed, may be null
public static String trimRight(String string,
Position pos)
Removes spaces (char <= 32) from end of this string, handling
null by returning null.
StringUtils.trimRight(null) = null
StringUtils.trimRight("") = ""
StringUtils.trimRight(" ") = ""
StringUtils.trimRight("abc") = "abc"
StringUtils.trimRight(" abc ") = " abc"
string - the string to be trimmed, may be null
public static String trimRight(byte[] bytes,
Position pos)
Removes spaces (char <= 32) from end of this string, handling
null by returning null.
StringUtils.trimRight(null) = null
StringUtils.trimRight("") = ""
StringUtils.trimRight(" ") = ""
StringUtils.trimRight("abc") = "abc"
StringUtils.trimRight(" abc ") = " abc"
bytes - the byte array to be trimmed, may be null
public static int trimRight(byte[] bytes,
int pos)
Removes spaces (char <= 32) from end of this array, handling
null by returning null.
StringUtils.trimRight(null) = null
StringUtils.trimRight("") = ""
StringUtils.trimRight(" ") = ""
StringUtils.trimRight("abc") = "abc"
StringUtils.trimRight(" abc ") = " abc"
bytes - the byte array to be trimmed, may be null
public static char charAt(String string,
int index)
string - The string which contains the dataindex - Current position in the string
public static byte byteAt(byte[] bytes,
int index)
bytes - The byte[] which contains the dataindex - Current position in the byte[]
public static String asciiBytesToString(byte[] bytes)
bytes - The byte array to transform
public static byte[] getBytesUtf8(String string)
string - The string to be transformed to a byte array
public static byte[] getBytesUtf8Ascii(String string)
string - The string to convert to byte[]
public static String getDefaultCharsetName()
public static boolean equals(String str1,
String str2)
Compares two Strings, returning true if they are equal.
nulls are handled without exceptions. Two
null 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
str1 - the first String, may be nullstr2 - the second String, may be null
true if the Strings are equal, case sensitive, or
both nullString.equals(Object)public static String listToString(List<?> list)
list - The list to transform to a string
public static String setToString(Set<?> set)
set - The set to transform to a string
public static String listToString(List<?> list,
String tabs)
list - The list to transform to a stringtabs - The tabs to add in ffront of the elements
public static String mapToString(Map<?,?> map)
map - The map to transform to a string
public static String mapToString(Map<?,?> map,
String tabs)
map - The map to transform to a stringtabs - The tabs to add in ffront of the elements
public static String toLowerCase(String value)
value - The String to lowercase
public static String toUpperCase(String value)
value - The String to uppercase
public static String upperCase(String str)
Converts a String to upper case as per String.toUpperCase().
A null input String returns null.
StringUtils.upperCase(null) = null
StringUtils.upperCase("") = ""
StringUtils.upperCase("aBc") = "ABC"
str - the String to upper case, may be null
null if null String inputpublic static String lowerCase(String str)
Converts a String to lower case as per String.toLowerCase().
A null input String returns null.
StringUtils.lowerCase(null) = null
StringUtils.lowerCase("") = ""
StringUtils.lowerCase("aBc") = "abc"
str - the String to lower case, may be null
null if null String inputpublic static String lowerCaseAscii(String str)
str - The String to lowercase
public static boolean isPrintableString(String str)
str - The String to check
true if the string is a PrintableString or is empty,
false otherwisepublic 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
str - the String to check, may be null
true if the String is not empty and not nullpublic static boolean isIA5String(String str)
str - The String to check
true if the string is an IA5String or is empty,
false otherwisepublic static boolean isValidUuid(String uuid)
uuid - the UUID to check for validity
public static String uuidToString(byte[] bytes)
bytes - bytes of a UUID
public static byte[] uuidToBytes(String string)
string - the string representation of an UUID
public static byte[] copy(byte[] value)
value - the byte array to copy
public static String getString(byte[] data,
int offset,
int length,
String charset)
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
public static String getString(byte[] data,
String charset)
data - the byte array to be encodedcharset - the desired character encoding
public static String getUUID(long value)
value - The least significant bits.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||