Package cz.martlin.xspf.util
Class ExceptionWrapper
- java.lang.Object
-
- cz.martlin.xspf.util.ExceptionWrapper
-
public class ExceptionWrapper extends Object
An utility, which encapsulates the checkedXSPFExceptionto unceckedXSPFRuntimeExceptionin 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceExceptionWrapper.ConsumerThrowing<T>AnConsumer, but with throwing exception.static interfaceExceptionWrapper.FunctionThrowing<IT,OT>AnFunction, but with throwing exception.static interfaceExceptionWrapper.PredicateThrowing<T>AnPredicate, but with throwing exception.
-
Constructor Summary
Constructors Constructor Description ExceptionWrapper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.function.Consumer<T>wrapConsumer(ExceptionWrapper.ConsumerThrowing<T> consumer)Wraps the given consumer (returns consumer catching all its exceptions and rethrowing asXSPFRuntimeException).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 asXSPFRuntimeException).static <T> java.util.function.Predicate<T>wrapPredicate(ExceptionWrapper.PredicateThrowing<T> predicate)Wraps the given predicated (returns predicate catching all its exceptions and rethrowing asXSPFRuntimeException).
-
-
-
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 asXSPFRuntimeException).- 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 asXSPFRuntimeException).- 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 asXSPFRuntimeException).- Type Parameters:
T-- Parameters:
predicate-- Returns:
-
-