Package com.restfb.util
Class StringUtils
- java.lang.Object
-
- com.restfb.util.StringUtils
-
public final class StringUtils extends Object
A collection of string-handling utility methods.- Since:
- 1.6
- Author:
- Mark Allen
-
-
Field Summary
Fields Modifier and Type Field Description static Charset
ENCODING_CHARSET
Default charset to use for encoding/decoding strings.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
fromInputStream(InputStream inputStream)
Builds and returns a string representation of the giveninputStream
.static boolean
isBlank(String string)
Isstring
blank (null or only whitespace)?static boolean
isNotBlank(String string)
Isstring
not blank (null or only whitespace)?static byte[]
toBytes(String string)
Convertsstring
to a byte array.static Integer
toInteger(String string)
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 Detail
-
ENCODING_CHARSET
public static final Charset ENCODING_CHARSET
Default charset to use for encoding/decoding strings.
-
-
Method Detail
-
isBlank
public static boolean isBlank(String string)
Isstring
blank (null or only whitespace)?- Parameters:
string
- The string to check.- Returns:
true
ifstring
is blank,false
otherwise.
-
isNotBlank
public static boolean isNotBlank(String string)
Isstring
not blank (null or only whitespace)?- Parameters:
string
- The string to check.- Returns:
true
ifstring
is not blank,false
otherwise.
-
trimToNull
public static String trimToNull(String string)
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
public static String trimToEmpty(String string)
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
public static byte[] toBytes(String string)
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
public static String toString(byte[] data)
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
public static String fromInputStream(InputStream inputStream) throws IOException
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
.
-
-