Class ExceptionWrapper


  • public class ExceptionWrapper
    extends Object
    An utility, which encapsulates the checked XSPFException to uncecked XSPFRuntimeException in context, where the checked exception is not allowed. Use as follows:
     something
     .map(ExceptionWrapper.wrapFunction(f -> new FileInputStream(f)))
     .filter(ExceptionWrapper.wrapPredicate(ins -> ins.read() > 0))
     .forEach(ExceptionWrapper.wrapConsumer(ins -> ins.close()))
     
     
    Author:
    martin
    • Constructor Detail

      • ExceptionWrapper

        public ExceptionWrapper()
    • Method Detail

      • wrapConsumer

        public static <T> java.util.function.Consumer<T> wrapConsumer​(ExceptionWrapper.ConsumerThrowing<T> consumer)
        Wraps the given consumer (returns consumer catching all its exceptions and rethrowing as XSPFRuntimeException).
        Type Parameters:
        T -
        Parameters:
        consumer -
        Returns:
      • wrapFunction

        public static <IT,​OT> java.util.function.Function<IT,​OT> wrapFunction​(ExceptionWrapper.FunctionThrowing<IT,​OT> function)
        Wraps the given function (returns function catching all its exceptions and rethrowing as XSPFRuntimeException).
        Type Parameters:
        IT -
        OT -
        Parameters:
        function -
        Returns:
      • wrapPredicate

        public static <T> java.util.function.Predicate<T> wrapPredicate​(ExceptionWrapper.PredicateThrowing<T> predicate)
        Wraps the given predicated (returns predicate catching all its exceptions and rethrowing as XSPFRuntimeException).
        Type Parameters:
        T -
        Parameters:
        predicate -
        Returns: