Class CheckedStream
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn exception that wraps another exception, but exposes itself as aRuntimeException. -
Method Summary
Modifier and TypeMethodDescriptionfilter(Stream<T> stream, Class<? extends Exception> throwableClass, CheckedPredicate<T, E> predicate) Performs aStream.filter(java.util.function.Predicate<? super T>)but accepts a predicate that can throw a checked-exception.flatMap(Stream<S> stream, Class<? extends Exception> throwableClass, CheckedFunction<S, Stream<? extends T>, E> flatMapFunction) Performs aStream.flatMap(java.util.function.Function<? super T, ? extends java.util.stream.Stream<? extends R>>)but accepts a function that can throw a checked-exceptionstatic <T,E extends Exception>
voidforEach(Stream<T> stream, Class<? extends Exception> throwableClass, CheckedConsumer<T, E> consumer) Performs aStream.forEach(java.util.function.Consumer<? super T>)but accepts a consumer that can throw a checked-exception.map(Stream<S> stream, Class<? extends Exception> throwableClass, CheckedFunction<S, T, E> mapFunction) Performs aStream.map(java.util.function.Function<? super T, ? extends R>)but accepts a function that can throw a checked-exception.mapIntStream(IntStream stream, Class<? extends Exception> throwableClass, CheckedIntFunction<T, E> mapFunc) Creates a new feature-list by mapping integers (from a range) each to an optional feature accepting a checked-exceptionmapToInt(Stream<S> stream, Class<? extends Exception> throwableClass, CheckedToIntFunction<S, E> mapFunction) Performs aStream.mapToInt(java.util.function.ToIntFunction<? super T>)but accepts a function that can throw a checked-exception.mapToObj(IntStream stream, Class<? extends Exception> throwableClass, CheckedIntFunction<T, E> mapFunction) Performs aIntStream.mapToObj(java.util.function.IntFunction<? extends U>)but accepts a function that can throw a checked-exception.
-
Method Details
-
forEach
public static <T,E extends Exception> void forEach(Stream<T> stream, Class<? extends Exception> throwableClass, CheckedConsumer<T, E> consumer) throws EPerforms aStream.forEach(java.util.function.Consumer<? super T>)but accepts a consumer that can throw a checked-exception.This uses some internal reflection trickery to suppress the checked exception, and then rethrow it.
As a side-effect, any runtime exceptions that are thrown during the function, will be rethrown wrapped inside a
CheckedStream.ConvertedToRuntimeException.- Type Parameters:
T- type to consume.E- exception that can be thrown bymapFunction.- Parameters:
stream- the stream to apply the map on.throwableClass- the class ofE.consumer- the function to call for each object in the stream.- Throws:
E- if the exception is thrown during mapping.
-
filter
public static <T,E extends Exception> Stream<T> filter(Stream<T> stream, Class<? extends Exception> throwableClass, CheckedPredicate<T, E> predicate) throws EPerforms aStream.filter(java.util.function.Predicate<? super T>)but accepts a predicate that can throw a checked-exception.This uses some internal reflection trickery to suppress the checked exception, and then rethrow it.
As a side-effect, any runtime exceptions that are thrown during the function, will be rethrown wrapped inside a
CheckedStream.ConvertedToRuntimeException.- Type Parameters:
T- type to consumeE- exception that can be thrown bymapFunction- Parameters:
stream- the stream to apply the map on.throwableClass- the class ofE.predicate- the predicate to call for each object in the stream.- Returns:
- elements from
streamthat match the predicate. - Throws:
E- if the exception is thrown during filtering.
-
map
public static <S,T, Stream<T> mapE extends Exception> (Stream<S> stream, Class<? extends Exception> throwableClass, CheckedFunction<S, T, throws EE> mapFunction) Performs aStream.map(java.util.function.Function<? super T, ? extends R>)but accepts a function that can throw a checked-exception.This uses some internal reflection trickery to suppress the checked exception, and then rethrow it.
As a side-effect, any runtime exceptions that are thrown during the function, will be rethrown wrapped inside a
CheckedStream.ConvertedToRuntimeException.- Type Parameters:
S- input-type to mapT- output-type of mapE- exception that can be thrown bymapFunction- Parameters:
stream- the stream to apply the map on.throwableClass- the class ofE.mapFunction- the function to use for mapping.- Returns:
- the output of the flatMap.
- Throws:
E- if the exception is thrown during mapping.
-
mapToInt
public static <S,E extends Exception> IntStream mapToInt(Stream<S> stream, Class<? extends Exception> throwableClass, CheckedToIntFunction<S, E> mapFunction) throws EPerforms aStream.mapToInt(java.util.function.ToIntFunction<? super T>)but accepts a function that can throw a checked-exception.This uses some internal reflection trickery to suppress the checked exception, and then rethrow it.
As a side-effect, any runtime exceptions that are thrown during the function, will be rethrown wrapped inside a
CheckedStream.ConvertedToRuntimeException.- Type Parameters:
S- input-type to mapE- exception that can be thrown bymapFunction- Parameters:
stream- the stream to apply the map on.throwableClass- the class ofE.mapFunction- the function to use for mapping.- Returns:
- the output of the flatMap.
- Throws:
E- if the exception is thrown during mapping.
-
mapIntStream
public static <T,E extends Exception> Stream<T> mapIntStream(IntStream stream, Class<? extends Exception> throwableClass, CheckedIntFunction<T, E> mapFunc) throws ECreates a new feature-list by mapping integers (from a range) each to an optional feature accepting a checked-exceptionThis uses some internal reflection trickery to suppress the checked exception, and then rethrow it.
- Type Parameters:
T- end-type for mappingE- an exception that be thrown during mapping- Parameters:
stream- stream ofints.throwableClass- the class ofE.mapFunc- function for mapping.- Returns:
- the stream after the mapping.
- Throws:
E- ifmapFuncthrows it.
-
mapToObj
public static <T,E extends Exception> Stream<T> mapToObj(IntStream stream, Class<? extends Exception> throwableClass, CheckedIntFunction<T, E> mapFunction) throws EPerforms aIntStream.mapToObj(java.util.function.IntFunction<? extends U>)but accepts a function that can throw a checked-exception.This uses some internal reflection trickery to suppress the checked exception, and then rethrow it.
As a side-effect, any runtime exceptions that are thrown during the function, will be rethrown wrapped inside a
CheckedStream.ConvertedToRuntimeException.- Type Parameters:
T- object-type to map-to.E- exception that can be thrown bymapFunction.- Parameters:
stream- the stream to apply the map on.throwableClass- the class ofE.mapFunction- the function to use for mapping.- Returns:
- the output of the flatMap.
- Throws:
E- if the exception is thrown during mapping.
-
flatMap
public static <S,T, Stream<T> flatMapE extends Exception> (Stream<S> stream, Class<? extends Exception> throwableClass, CheckedFunction<S, Stream<? extends T>, throws EE> flatMapFunction) Performs aStream.flatMap(java.util.function.Function<? super T, ? extends java.util.stream.Stream<? extends R>>)but accepts a function that can throw a checked-exceptionThis uses some internal reflection trickery to suppress the checked exception, and then rethrow it.
As a side-effect, any runtime exceptions that are thrown during the function, will be rethrown wrapped inside a
CheckedStream.ConvertedToRuntimeException.- Type Parameters:
S- input-type to flatMapT- output-type of flatMapE- exception that can be thrown byflatMapFunction.- Parameters:
stream- the stream to apply the flatMap on.throwableClass- the class ofE.flatMapFunction- the function to use for flatMapping.- Returns:
- the output of the flatMap.
- Throws:
E- if the exception.
-