com.restfb.util
Class StringUtils

java.lang.Object
  extended by 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
static String ENCODING_CHARSET
          Default charset to use for encoding/decoding strings.
 
Method Summary
static String fromInputStream(InputStream inputStream)
          Builds and returns a string representation of the given inputStream .
static boolean isBlank(String string)
          Is string blank (null or only whitespace)?
static String join(List<String> list)
          Joins the given list into a comma-separated string.
static String join(String[] array)
          Joins the given array into a comma-separated string.
static byte[] toBytes(String string)
          Converts string to a byte array.
static String trimToEmpty(String string)
          Returns a trimmed version of string, or an empty string if string is null or the trimmed version is a blank string.
static String trimToNull(String string)
          Returns a trimmed version of string, or null if string is null or the trimmed version is a blank string.
static String urlDecode(String string)
          URL-decodes a string.
static String urlEncode(String string)
          URL-encodes a string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODING_CHARSET

public static final String ENCODING_CHARSET
Default charset to use for encoding/decoding strings.

See Also:
Constant Field Values
Method Detail

isBlank

public static boolean isBlank(String string)
Is string blank (null or only whitespace)?

Parameters:
string - The string to check.
Returns:
true if string is blank, false otherwise.

trimToNull

public static String trimToNull(String string)
Returns a trimmed version of string, or null if string is null or the trimmed version is a blank string.

Parameters:
string - The string to trim.
Returns:
A trimmed version of string, or null if string is null or the trimmed version is a blank string.

trimToEmpty

public static String trimToEmpty(String string)
Returns a trimmed version of string, or an empty string if string is null or the trimmed version is a blank string.

Parameters:
string - The string to trim.
Returns:
A trimmed version of string, or an empty string if string is null or the trimmed version is a blank string.

urlEncode

public static String urlEncode(String string)
URL-encodes a string.

Assumes string is in "UTF-8" format.

Parameters:
string - The string to URL-encode.
Returns:
The URL-encoded version of the input string, or null if string is null.
Throws:
IllegalStateException - If unable to URL-encode because the JVM doesn't support "UTF-8".

urlDecode

public static String urlDecode(String string)
URL-decodes a string.

Assumes string is in "UTF-8" format.

Parameters:
string - The string to URL-decode.
Returns:
The URL-decoded version of the input string, or null if string is null.
Throws:
IllegalStateException - If unable to URL-decode because the JVM doesn't support "UTF-8".
Since:
1.6.5

toBytes

public static byte[] toBytes(String string)
Converts string to a byte array.

Assumes string is in "UTF-8" format.

Parameters:
string - The string to convert to a byte array.
Returns:
A byte array representation of string.
Throws:
NullPointerException - If string is null.
IllegalStateException - If unable to URL-encode because the JVM doesn't support "UTF-8".

fromInputStream

public static String fromInputStream(InputStream inputStream)
                              throws IOException
Builds and returns a string representation of the given inputStream .

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 the inputStream.

join

public static String join(String[] array)
Joins the given array into a comma-separated string.

Parameters:
array - The array to join.
Returns:
A comma-separated string representation of the given array.

join

public static String join(List<String> list)
Joins the given list into a comma-separated string.

Parameters:
list - The list to join.
Returns:
A comma-separated string representation of the given list.


RestFB 1.6.8. Copyright © 2010-2011 Mark Allen. All Rights Reserved.