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
Modifier and TypeFieldDescriptionstatic final Charset
Default charset to use for encoding/decoding strings. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
fromInputStream
(InputStream inputStream) Builds and returns a string representation of the giveninputStream
.static boolean
Isstring
blank (null or only whitespace)?static boolean
isNotBlank
(String string) Isstring
not blank (null or only whitespace)?static byte[]
Convertsstring
to a byte array.static Integer
Returns anInteger
representation of the givenstring
, ornull
if it's not a validInteger
.static String
toString
(byte[] data) Convertsdata
to a string inENCODING_CHARSET
format.static String
trimToEmpty
(String string) Returns a trimmed version ofstring
, or an empty string ifstring
isnull
or the trimmed version is a blank string.static String
trimToNull
(String string) Returns a trimmed version ofstring
, ornull
ifstring
isnull
or the trimmed version is a blank string.
-
Field Details
-
ENCODING_CHARSET
Default charset to use for encoding/decoding strings.
-
-
Method Details
-
isBlank
Isstring
blank (null or only whitespace)?- Parameters:
string
- The string to check.- Returns:
true
ifstring
is blank,false
otherwise.
-
isNotBlank
Isstring
not blank (null or only whitespace)?- Parameters:
string
- The string to check.- Returns:
true
ifstring
is not blank,false
otherwise.
-
trimToNull
Returns a trimmed version ofstring
, ornull
ifstring
isnull
or the trimmed version is a blank string.- Parameters:
string
- The string to trim.- Returns:
- A trimmed version of
string
, ornull
ifstring
isnull
or the trimmed version is a blank string.
-
trimToEmpty
Returns a trimmed version ofstring
, or an empty string ifstring
isnull
or the trimmed version is a blank string.- Parameters:
string
- The string to trim.- Returns:
- A trimmed version of
string
, or an empty string ifstring
isnull
or the trimmed version is a blank string.
-
toBytes
Convertsstring
to a byte array.Assumes
string
is inENCODING_CHARSET
format.- Parameters:
string
- The string to convert to a byte array.- Returns:
- A byte array representation of
string
. - Throws:
NullPointerException
- Ifstring
isnull
.IllegalStateException
- If unable to convert because the JVM doesn't supportENCODING_CHARSET
.
-
toString
Convertsdata
to a string inENCODING_CHARSET
format.- Parameters:
data
- The data to convert to a string.- Returns:
- A string representation of
data
. - Throws:
NullPointerException
- Ifdata
isnull
.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 anInteger
representation of the givenstring
, ornull
if it's not a validInteger
.- Parameters:
string
- The string to process.- Returns:
- The
Integer
representation ofstring
, ornull
ifstring
isnull
or not a validInteger
.
-