Class Utils


  • public final class Utils
    extends Object
    An assortment of various utility methods.
    Author:
    Arjan Tijms
    • Field Detail

      • validateRequestMethod

        public static final Method validateRequestMethod
      • cleanSubjectMethod

        public static final Method cleanSubjectMethod
    • Method Detail

      • notNull

        public static boolean notNull​(Object... objects)
      • isEmpty

        public static boolean isEmpty​(String string)
        Returns true if the given string is null or is empty.
        Parameters:
        string - The string to be checked on emptiness.
        Returns:
        True if the given string is null or is empty.
      • isEmpty

        public static boolean isEmpty​(Object[] array)
        Returns true if the given array is null or is empty.
        Parameters:
        array - The array to be checked on emptiness.
        Returns:
        true if the given array is null or is empty.
      • isEmpty

        public static boolean isEmpty​(Collection<?> collection)
        Returns true if the given collection is null or is empty.
        Parameters:
        collection - The collection to be checked on emptiness.
        Returns:
        true if the given collection is null or is empty.
      • isOneOf

        @SafeVarargs
        public static <T> boolean isOneOf​(T object,
                                          T... objects)
        Returns true if the given object equals one of the given objects.
        Type Parameters:
        T - The generic object type.
        Parameters:
        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.
        Returns:
        true if the given object equals one of the given objects.
      • getParam

        public static <T> T getParam​(jakarta.interceptor.InvocationContext invocationContext,
                                     int param)
      • getBaseURL

        public static String getBaseURL​(jakarta.servlet.http.HttpServletRequest request)
      • redirect

        public static void redirect​(jakarta.servlet.http.HttpServletResponse response,
                                    String location)
      • getELProcessor

        public static jakarta.el.ELProcessor getELProcessor​(String name,
                                                            Object bean)
      • getELProcessor

        public static jakarta.el.ELProcessor getELProcessor​(String name1,
                                                            Object bean1,
                                                            String name2,
                                                            Object bean2)
      • toCallerPrincipal

        public static jakarta.security.enterprise.CallerPrincipal toCallerPrincipal​(Principal principal)
      • redirect

        public static void redirect​(jakarta.servlet.http.HttpServletRequest request,
                                    jakarta.servlet.http.HttpServletResponse response,
                                    String location)
      • isFacesAjaxRequest

        public static boolean isFacesAjaxRequest​(jakarta.servlet.http.HttpServletRequest request)
      • unmodifiableSet

        public static <E> Set<E> unmodifiableSet​(Object... values)
      • encodeURL

        public static String encodeURL​(String string)
      • decodeURL

        public static String decodeURL​(String string)
      • getSingleParameterFromState

        public static String getSingleParameterFromState​(String state,
                                                         String paramName)
      • toParameterMap

        public static Map<String,​List<String>> toParameterMap​(String queryString)
        Converts the given request query string to request parameter values map.
        Parameters:
        queryString - The request query string.
        Returns:
        The request query string as request parameter values map.
      • toQueryString

        public static String toQueryString​(Map<String,​List<String>> parameterMap)
        Converts the given request parameter values map to request query string.
        Parameters:
        parameterMap - The request parameter values map.
        Returns:
        The request parameter values map as request query string.
      • getSingleParameterFromQueryString

        public static String getSingleParameterFromQueryString​(String queryString,
                                                               String paramName)
      • serializeURLSafe

        public static String serializeURLSafe​(String string)
        Serialize the given string to the short possible unique URL-safe representation. The current implementation will decode the given string with UTF-8 and then compress it with ZLIB using "best compression" algorithm and then Base64-encode the resulting bytes without the = padding, whereafter the Base64 characters + 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).
        Parameters:
        string - The string to be serialized.
        Returns:
        The serialized URL-safe string, or null when the given string is itself null.
      • unserializeURLSafe

        public static String unserializeURLSafe​(String string)
        Unserialize the given serialized URL-safe string. This does the inverse of serializeURLSafe(String).
        Parameters:
        string - The serialized URL-safe string to be unserialized.
        Returns:
        The unserialized string, or null when the given string is by itself null.
        Throws:
        IllegalArgumentException - When the given serialized URL-safe string is not in valid format as returned by serializeURLSafe(String).
      • toByteArray

        public static byte[] toByteArray​(InputStream input)
                                  throws IOException
        Read the given input stream into a byte array. The given input stream will implicitly be closed after streaming, regardless of whether an exception is been thrown or not.
        Parameters:
        input - The input stream.
        Returns:
        The input stream as a byte array.
        Throws:
        IOException - When an I/O error occurs.
      • isImplementationOf

        public static boolean isImplementationOf​(Method implementationMethod,
                                                 Method interfaceMethod)