Package com.restfb.util
Class StringUtils
java.lang.Object
com.restfb.util.StringUtils
A collection of string-handling utility methods.
- Since:
- 1.6
- Author:
- Mark Allen
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CharsetDefault charset to use for encoding/decoding strings. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringfromInputStream(InputStream inputStream) Builds and returns a string representation of the giveninputStream.static booleanIsstringblank (null or only whitespace)?static booleanisNotBlank(String string) Isstringnot blank (null or only whitespace)?static byte[]Convertsstringto a byte array.static IntegerReturns anIntegerrepresentation of the givenstring, ornullif it's not a validInteger.static StringtoString(byte[] data) Convertsdatato a string inENCODING_CHARSETformat.static StringtrimToEmpty(String string) Returns a trimmed version ofstring, or an empty string ifstringisnullor the trimmed version is a blank string.static StringtrimToNull(String string) Returns a trimmed version ofstring, ornullifstringisnullor the trimmed version is a blank string.
-
Field Details
-
ENCODING_CHARSET
Default charset to use for encoding/decoding strings.
-
-
Method Details
-
isBlank
Isstringblank (null or only whitespace)?- Parameters:
string- The string to check.- Returns:
trueifstringis blank,falseotherwise.
-
isNotBlank
Isstringnot blank (null or only whitespace)?- Parameters:
string- The string to check.- Returns:
trueifstringis not blank,falseotherwise.
-
trimToNull
Returns a trimmed version ofstring, ornullifstringisnullor the trimmed version is a blank string.- Parameters:
string- The string to trim.- Returns:
- A trimmed version of
string, ornullifstringisnullor the trimmed version is a blank string.
-
trimToEmpty
Returns a trimmed version ofstring, or an empty string ifstringisnullor the trimmed version is a blank string.- Parameters:
string- The string to trim.- Returns:
- A trimmed version of
string, or an empty string ifstringisnullor the trimmed version is a blank string.
-
toBytes
Convertsstringto a byte array.Assumes
stringis inENCODING_CHARSETformat.- Parameters:
string- The string to convert to a byte array.- Returns:
- A byte array representation of
string. - Throws:
NullPointerException- Ifstringisnull.IllegalStateException- If unable to convert because the JVM doesn't supportENCODING_CHARSET.
-
toString
Convertsdatato a string inENCODING_CHARSETformat.- Parameters:
data- The data to convert to a string.- Returns:
- A string representation of
data. - Throws:
NullPointerException- Ifdataisnull.IllegalStateException- If unable to convert because the JVM doesn't supportENCODING_CHARSET.- Since:
- 1.6.13
-
fromInputStream
Builds and returns a string representation of the giveninputStream.- Parameters:
inputStream- The stream from which a string representation is built.- Returns:
- A string representation of the given
inputStream. - Throws:
IOException- If an error occurs while processing theinputStream.
-
toInteger
Returns anIntegerrepresentation of the givenstring, ornullif it's not a validInteger.- Parameters:
string- The string to process.- Returns:
- The
Integerrepresentation ofstring, ornullifstringisnullor not a validInteger.
-