Package org.apache.hc.core5.util
Class TextUtils
- java.lang.Object
-
- org.apache.hc.core5.util.TextUtils
-
public final class TextUtils extends java.lang.ObjectTests and converts Strings and CharSequence.- Since:
- 4.3
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static bytecastAsByte(int c)Casts character to byte filtering non-visible and non-ASCII characters before conversion.static booleancontainsBlanks(java.lang.CharSequence s)Tests whether a CharSequence contains any whitespace.static booleanisAllASCII(java.lang.CharSequence s)Determines whether the givenCharSequencecontains only ASCII characters.static booleanisBlank(java.lang.CharSequence s)Checks if a CharSequence is empty (""), null or whitespace only.static booleanisEmpty(java.lang.CharSequence s)Tests whether the parameter is null or of zero length.static booleanisHex(char c)Tests whether the given character is an ASCII hexadecimal digit.static booleanisPrintable(int c)Tests whether a character can be written to an HTTP protocol line without replacing it.static intlength(java.lang.CharSequence cs)Gets a CharSequence length or0if the CharSequence isnull.static java.lang.StringtoHexString(byte[] bytes)static java.lang.StringtoLowerCase(java.lang.String s)Converts a String to its lower case representation usingLocale.ROOT.
-
-
-
Method Detail
-
isEmpty
public static boolean isEmpty(java.lang.CharSequence s)
Tests whether the parameter is null or of zero length.- Parameters:
s- The CharSequence to test.- Returns:
- whether the parameter is null or of zero length.
-
isBlank
public static boolean isBlank(java.lang.CharSequence s)
Checks if a CharSequence is empty (""), null or whitespace only.
Whitespace is defined by
Character.isWhitespace(char).TextUtils.isBlank(null) = true TextUtils.isBlank("") = true TextUtils.isBlank(" ") = true TextUtils.isBlank("abg") = false TextUtils.isBlank(" abg ") = false- Parameters:
s- the CharSequence to check, may be null- Returns:
trueif the CharSequence is null, empty or whitespace only
-
length
public static int length(java.lang.CharSequence cs)
Gets a CharSequence length or0if the CharSequence isnull.- Parameters:
cs- a CharSequence ornull- Returns:
- CharSequence length or
0if the CharSequence isnull. - Since:
- 5.1
-
containsBlanks
public static boolean containsBlanks(java.lang.CharSequence s)
Tests whether a CharSequence contains any whitespace.- Parameters:
s- The CharSequence to test.- Returns:
- whether a CharSequence contains any whitespace.
- Since:
- 4.4
-
toHexString
public static java.lang.String toHexString(byte[] bytes)
-
toLowerCase
public static java.lang.String toLowerCase(java.lang.String s)
Converts a String to its lower case representation usingLocale.ROOT.- Parameters:
s- The String to convert- Returns:
- The converted String.
- Since:
- 5.2
-
isAllASCII
public static boolean isAllASCII(java.lang.CharSequence s)
Determines whether the givenCharSequencecontains only ASCII characters.- Parameters:
s- theCharSequenceto check- Returns:
- true if the
CharSequencecontains only ASCII characters, false otherwise - Throws:
java.lang.IllegalArgumentException- if the inputCharSequenceis null- Since:
- 5.3
-
castAsByte
@Internal public static byte castAsByte(int c)
Casts character to byte filtering non-visible and non-ASCII characters before conversion.- Parameters:
c- The character to cast.- Returns:
- The given character or
'?'. - Since:
- 5.2
-
isHex
public static boolean isHex(char c)
Tests whether the given character is an ASCII hexadecimal digit.Accepts
'0'..'9','A'..'F', and'a'..'f'only. This method does not consider non-ASCII numerals or fullwidth forms.- Parameters:
c- the character to test- Returns:
trueifcis an ASCII hex digit,falseotherwise- Since:
- 5.4
-
isPrintable
@Internal public static boolean isPrintable(int c)
Tests whether a character can be written to an HTTP protocol line without replacing it. Horizontal tab is permitted for compatibility.- Parameters:
c- The character to test.- Returns:
trueif the character does not need filtering.- Since:
- 5.5
-
-