org.opensaml.xml.util
Class DatatypeHelper

java.lang.Object
  extended by org.opensaml.xml.util.DatatypeHelper

public final class DatatypeHelper
extends Object

Helper class for working with various datatypes.


Method Summary
static byte[] fileToByteArray(File file)
          Reads the contents of a file in to a byte array.
static String inputstreamToString(InputStream input, CharsetDecoder decoder)
          Reads an input stream into a string.
static byte[] intToByteArray(int integer)
          Converts an integer into an unsigned 4-byte array.
static boolean isEmpty(String s)
          A "safe" null/empty check for strings.
static String listToStringValue(List<String> values, String delimiter)
          Converts a List of strings into a single string, with values separated by a specified delimiter.
static
<T> boolean
safeEquals(T s1, T s2)
          Compares two strings for equality, allowing for nulls.
static String safeTrim(String s)
          A safe string trim that handles nulls.
static String safeTrimOrNullString(String s)
          Removes preceeding or proceeding whitespace from a string or return null if the string is null or of zero length after trimming (i.e.
static List<String> stringToList(String string, String delimiter)
          Converts a delimited string into a list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isEmpty

public static boolean isEmpty(String s)
A "safe" null/empty check for strings.

Parameters:
s - The string to check
Returns:
true if the string is null or the trimmed string is length zero

safeEquals

public static <T> boolean safeEquals(T s1,
                                     T s2)
Compares two strings for equality, allowing for nulls.

Type Parameters:
T - type of object to compare
Parameters:
s1 - The first operand
s2 - The second operand
Returns:
true if both are null or both are non-null and the same strng value

safeTrim

public static String safeTrim(String s)
A safe string trim that handles nulls.

Parameters:
s - the string to trim
Returns:
the trimmed string or null if the given string was null

safeTrimOrNullString

public static String safeTrimOrNullString(String s)
Removes preceeding or proceeding whitespace from a string or return null if the string is null or of zero length after trimming (i.e. if the string only contained whitespace).

Parameters:
s - the string to trim
Returns:
the trimmed string or null

intToByteArray

public static byte[] intToByteArray(int integer)
Converts an integer into an unsigned 4-byte array.

Parameters:
integer - integer to convert
Returns:
4-byte array representing integer

fileToByteArray

public static byte[] fileToByteArray(File file)
                              throws IOException
Reads the contents of a file in to a byte array.

Parameters:
file - file to read
Returns:
the byte contents of the file
Throws:
IOException - throw if there is a problem reading the file in to the byte array

inputstreamToString

public static String inputstreamToString(InputStream input,
                                         CharsetDecoder decoder)
                                  throws IOException
Reads an input stream into a string. The provide stream is not closed.

Parameters:
input - the input stream to read
decoder - character decoder to use, if null, system default character set is used
Returns:
the string read from the stream
Throws:
IOException - thrown if there is a problem reading from the stream and decoding it

stringToList

public static List<String> stringToList(String string,
                                        String delimiter)
Converts a delimited string into a list.

Parameters:
string - the string to be split into a list
delimiter - the delimiter between values. This string may contain multiple delimiter characters, as allowed by StringTokenizer
Returns:
the list of values or an empty list if the given string is null or empty

listToStringValue

public static String listToStringValue(List<String> values,
                                       String delimiter)
Converts a List of strings into a single string, with values separated by a specified delimiter.

Parameters:
values - list of strings
delimiter - the delimiter used between values
Returns:
delimited string of values


Copyright © 2006-2011 Internet2. All Rights Reserved.