public final class Utils extends Object
| Modifier and Type | Method and Description |
|---|---|
static IOException |
close(Closeable resource)
Check if the given resource is not
null and then close it, whereby any caught IOException
is been returned instead of thrown, so that the caller can if necessary handle (log) or just ignore it without
the need to put another try-catch. |
static <T> T |
coalesce(T... objects)
Returns the first non-
null object of the argument list, or null if there is no such
element. |
static String |
formatRFC1123(Date date)
Formats the given
Date to a string in RFC1123 format. |
static boolean |
isEmpty(Collection<?> collection)
Returns true if the given collection is null or is empty.
|
static boolean |
isEmpty(Object value)
Returns true if the given value is null or is empty.
|
static boolean |
isEmpty(Object[] array)
Returns true if the given array is null or is empty.
|
static boolean |
isEmpty(String string)
Returns true if the given string is null or is empty.
|
static <T> boolean |
isOneOf(T object,
T... objects)
Returns
true if the given object equals one of the given objects. |
static Date |
parseRFC1123(String string)
Parses the given string in RFC1123 format to a
Date object. |
static String |
serializeURLSafe(String string)
Serialize the given string to the short possible unique URL-safe representation.
|
static long |
stream(InputStream input,
OutputStream output)
Stream the given input to the given output by NIO
ByteBuffer. |
static <T> Set<T> |
unmodifiableSet(Object... values)
Creates an unmodifiable set based on the given values.
|
static String |
unserializeURLSafe(String string)
Unserialize the given serialized URL-safe string.
|
public static boolean isEmpty(String string)
string - The string to be checked on emptiness.public static boolean isEmpty(Object[] array)
array - The array to be checked on emptiness.public static boolean isEmpty(Collection<?> collection)
collection - The collection to be checked on emptiness.public static boolean isEmpty(Object value)
value - The value to be checked on emptiness.public static <T> T coalesce(T... objects)
null object of the argument list, or null if there is no such
element.T - The generic object type.objects - The argument list of objects to be tested for non-null.null object of the argument list, or null if there is no such
element.public static <T> boolean isOneOf(T object,
T... objects)
true if the given object equals one of the given objects.T - The generic object type.object - The object to be checked if it equals one of the given objects.objects - The argument list of objects to be tested for equality.true if the given object equals one of the given objects.public static long stream(InputStream input, OutputStream output) throws IOException
ByteBuffer. Both the input and output streams will
implicitly be closed after streaming, regardless of whether an exception is been thrown or not.input - The input stream.output - The output stream.IOException - When an I/O error occurs.public static IOException close(Closeable resource)
null and then close it, whereby any caught IOException
is been returned instead of thrown, so that the caller can if necessary handle (log) or just ignore it without
the need to put another try-catch.resource - The closeable resource to be closed.IOException, or null if none is been thrown.public static <T> Set<T> unmodifiableSet(Object... values)
ClassCastException.values - The values to create an unmodifiable set for.ClassCastException - When one of the values or one of the arrays or collections is of wrong type.public static String formatRFC1123(Date date)
Date to a string in RFC1123 format. This format is used in HTTP headers and in
JavaScript Date constructor.date - The Date to be formatted to a string in RFC1123 format.public static Date parseRFC1123(String string) throws ParseException
Date object.string - The string in RFC1123 format to be parsed to a Date object.Date.ParseException - When the given string is not in RFC1123 format.public static String serializeURLSafe(String string)
/, + and
= are been replaced by respectively ~, - and _ to make it
URL-safe (so that no platform-sensitive URL-encoding needs to be done when used in URLs).string - The string to be serialized.null when the given string is itself null.public static String unserializeURLSafe(String string)
serializeURLSafe(String).string - The serialized URL-safe string to be unserialized.null when the given string is by itself null.IllegalArgumentException - When the given serialized URL-safe string is not in valid format as returned by
serializeURLSafe(String).