Package org.apache.commons.io.function
Interface IOStream<T>
-
- Type Parameters:
T
- the type of the stream elements.
- All Superinterfaces:
java.lang.AutoCloseable
,java.io.Closeable
,IOBaseStream<T,IOStream<T>,java.util.stream.Stream<T>>
public interface IOStream<T> extends IOBaseStream<T,IOStream<T>,java.util.stream.Stream<T>>
LikeStream
but throwsIOException
.- Since:
- 2.12.0
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description static <T> IOStream<T>
adapt(java.util.stream.Stream<T> stream)
Constructs a new IOStream for the given Stream.default boolean
allMatch(IOPredicate<? super T> predicate)
LikeStream.allMatch(java.util.function.Predicate)
but throwsIOException
.default boolean
anyMatch(IOPredicate<? super T> predicate)
LikeStream.anyMatch(java.util.function.Predicate)
but throwsIOException
.default <R,A>
Rcollect(java.util.stream.Collector<? super T,A,R> collector)
TODO Package-private for now, needs IOCollector? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one.default <R> R
collect(IOSupplier<R> supplier, IOBiConsumer<R,? super T> accumulator, IOBiConsumer<R,R> combiner)
LikeStream.collect(java.util.function.Supplier, java.util.function.BiConsumer, java.util.function.BiConsumer)
.default long
count()
LikeStream.count()
.default IOStream<T>
distinct()
LikeStream.distinct()
.static <T> IOStream<T>
empty()
This class' version ofStream.empty()
.default IOStream<T>
filter(IOPredicate<? super T> predicate)
LikeStream.filter(java.util.function.Predicate)
.default java.util.Optional<T>
findAny()
LikeStream.findAny()
.default java.util.Optional<T>
findFirst()
LikeStream.findFirst()
.default <R> IOStream<R>
flatMap(IOFunction<? super T,? extends IOStream<? extends R>> mapper)
LikeStream.flatMap(java.util.function.Function)
.default java.util.stream.DoubleStream
flatMapToDouble(IOFunction<? super T,? extends java.util.stream.DoubleStream> mapper)
TODO Package-private for now, needs IODoubleStream? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one.default java.util.stream.IntStream
flatMapToInt(IOFunction<? super T,? extends java.util.stream.IntStream> mapper)
TODO Package-private for now, needs IOIntStream? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one.default java.util.stream.LongStream
flatMapToLong(IOFunction<? super T,? extends java.util.stream.LongStream> mapper)
TODO Package-private for now, needs IOLongStream? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one.default void
forAll(IOConsumer<T> action)
Performs an action for each element gathering any exceptions.default void
forAll(IOConsumer<T> action, java.util.function.BiFunction<java.lang.Integer,java.io.IOException,java.io.IOException> exSupplier)
Performs an action for each element gathering any exceptions.default void
forEach(IOConsumer<? super T> action)
LikeStream.forEach(java.util.function.Consumer)
but throwsIOException
.default void
forEachOrdered(IOConsumer<? super T> action)
LikeStream.forEachOrdered(java.util.function.Consumer)
.static <T> IOStream<T>
iterate(T seed, IOUnaryOperator<T> f)
LikeStream.iterate(Object, UnaryOperator)
but for IO.default IOStream<T>
limit(long maxSize)
LikeStream.limit(long)
.default <R> IOStream<R>
map(IOFunction<? super T,? extends R> mapper)
LikeStream.map(java.util.function.Function)
.default java.util.stream.DoubleStream
mapToDouble(java.util.function.ToDoubleFunction<? super T> mapper)
TODO Package-private for now, needs IOToDoubleFunction? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one.default java.util.stream.IntStream
mapToInt(java.util.function.ToIntFunction<? super T> mapper)
TODO Package-private for now, needs IOToIntFunction? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one.default java.util.stream.LongStream
mapToLong(java.util.function.ToLongFunction<? super T> mapper)
TODO Package-private for now, needs IOToLongFunction? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one.default java.util.Optional<T>
max(IOComparator<? super T> comparator)
LikeStream.max(java.util.Comparator)
.default java.util.Optional<T>
min(IOComparator<? super T> comparator)
LikeStream.min(java.util.Comparator)
.default boolean
noneMatch(IOPredicate<? super T> predicate)
LikeStream.noneMatch(java.util.function.Predicate)
.static <T> IOStream<T>
of(java.lang.Iterable<T> values)
Null-safe version ofStreamSupport.stream(java.util.Spliterator, boolean)
.static <T> IOStream<T>
of(T t)
Returns a sequentialIOStreamImpl
containing a single element.static <T> IOStream<T>
of(T... values)
Null-safe version ofStream.of(Object[])
for an IO stream.default IOStream<T>
peek(IOConsumer<? super T> action)
LikeStream.peek(java.util.function.Consumer)
.default java.util.Optional<T>
reduce(IOBinaryOperator<T> accumulator)
LikeStream.reduce(java.util.function.BinaryOperator)
.default T
reduce(T identity, IOBinaryOperator<T> accumulator)
LikeStream.reduce(Object, java.util.function.BinaryOperator)
.default <U> U
reduce(U identity, IOBiFunction<U,? super T,U> accumulator, IOBinaryOperator<U> combiner)
LikeStream.reduce(Object, BiFunction, java.util.function.BinaryOperator)
.default IOStream<T>
skip(long n)
LikeStream.skip(long)
.default IOStream<T>
sorted()
LikeStream.sorted()
.default IOStream<T>
sorted(IOComparator<? super T> comparator)
LikeStream.sorted(java.util.Comparator)
.default java.lang.Object[]
toArray()
LikeStream.toArray()
.default <A> A[]
toArray(java.util.function.IntFunction<A[]> generator)
TODO Package-private for now, needs IOIntFunction? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one.-
Methods inherited from interface org.apache.commons.io.function.IOBaseStream
asBaseStream, close, isParallel, iterator, onClose, parallel, sequential, spliterator, unordered, unwrap, wrap
-
-
-
-
Method Detail
-
adapt
static <T> IOStream<T> adapt(java.util.stream.Stream<T> stream)
Constructs a new IOStream for the given Stream.- Type Parameters:
T
- the type of the stream elements.- Parameters:
stream
- The stream to delegate.- Returns:
- a new IOStream.
-
empty
static <T> IOStream<T> empty()
This class' version ofStream.empty()
.- Type Parameters:
T
- the type of the stream elements- Returns:
- an empty sequential
IOStreamImpl
. - See Also:
Stream.empty()
-
iterate
static <T> IOStream<T> iterate(T seed, IOUnaryOperator<T> f)
LikeStream.iterate(Object, UnaryOperator)
but for IO.- Type Parameters:
T
- the type of stream elements.- Parameters:
seed
- the initial element.f
- a function to be applied to the previous element to produce a new element.- Returns:
- a new sequential
IOStream
.
-
of
static <T> IOStream<T> of(java.lang.Iterable<T> values)
Null-safe version ofStreamSupport.stream(java.util.Spliterator, boolean)
. Copied from Apache Commons Lang.- Type Parameters:
T
- the type of stream elements.- Parameters:
values
- the elements of the new stream, may benull
.- Returns:
- the new stream on
values
orStream.empty()
.
-
of
@SafeVarargs static <T> IOStream<T> of(T... values)
Null-safe version ofStream.of(Object[])
for an IO stream.- Type Parameters:
T
- the type of stream elements.- Parameters:
values
- the elements of the new stream, may benull
.- Returns:
- the new stream on
values
orStream.empty()
.
-
of
static <T> IOStream<T> of(T t)
Returns a sequentialIOStreamImpl
containing a single element.- Type Parameters:
T
- the type of stream elements- Parameters:
t
- the single element- Returns:
- a singleton sequential stream
-
allMatch
default boolean allMatch(IOPredicate<? super T> predicate) throws java.io.IOException
LikeStream.allMatch(java.util.function.Predicate)
but throwsIOException
.- Parameters:
predicate
-Stream.allMatch(java.util.function.Predicate)
.- Returns:
- Like
Stream.allMatch(java.util.function.Predicate)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
anyMatch
default boolean anyMatch(IOPredicate<? super T> predicate) throws java.io.IOException
LikeStream.anyMatch(java.util.function.Predicate)
but throwsIOException
.- Parameters:
predicate
-Stream.anyMatch(java.util.function.Predicate)
.- Returns:
- Like
Stream.anyMatch(java.util.function.Predicate)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
collect
default <R,A> R collect(java.util.stream.Collector<? super T,A,R> collector)
TODO Package-private for now, needs IOCollector? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one. It would be ideal to have only one. LikeStream.collect(Collector)
. Package private for now.- Type Parameters:
R
- LikeStream.collect(Collector)
.A
- LikeStream.collect(Collector)
.- Parameters:
collector
- LikeStream.collect(Collector)
.- Returns:
- Like
Stream.collect(Collector)
.
-
collect
default <R> R collect(IOSupplier<R> supplier, IOBiConsumer<R,? super T> accumulator, IOBiConsumer<R,R> combiner) throws java.io.IOException
LikeStream.collect(java.util.function.Supplier, java.util.function.BiConsumer, java.util.function.BiConsumer)
.- Type Parameters:
R
- LikeStream.collect(java.util.function.Supplier, java.util.function.BiConsumer, java.util.function.BiConsumer)
.- Parameters:
supplier
- LikeStream.collect(java.util.function.Supplier, java.util.function.BiConsumer, java.util.function.BiConsumer)
.accumulator
- LikeStream.collect(java.util.function.Supplier, java.util.function.BiConsumer, java.util.function.BiConsumer)
.combiner
- LikeStream.collect(java.util.function.Supplier, java.util.function.BiConsumer, java.util.function.BiConsumer)
.- Returns:
- Like
Stream.collect(java.util.function.Supplier, java.util.function.BiConsumer, java.util.function.BiConsumer)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
count
default long count()
LikeStream.count()
.- Returns:
- Like
Stream.count()
.
-
filter
default IOStream<T> filter(IOPredicate<? super T> predicate) throws java.io.IOException
LikeStream.filter(java.util.function.Predicate)
.- Parameters:
predicate
- LikeStream.filter(java.util.function.Predicate)
.- Returns:
- Like
Stream.filter(java.util.function.Predicate)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
findAny
default java.util.Optional<T> findAny()
LikeStream.findAny()
.- Returns:
- Like
Stream.findAny()
.
-
findFirst
default java.util.Optional<T> findFirst()
LikeStream.findFirst()
.- Returns:
- Like
Stream.findFirst()
.
-
flatMap
default <R> IOStream<R> flatMap(IOFunction<? super T,? extends IOStream<? extends R>> mapper) throws java.io.IOException
LikeStream.flatMap(java.util.function.Function)
.- Type Parameters:
R
- LikeStream.flatMap(java.util.function.Function)
.- Parameters:
mapper
- LikeStream.flatMap(java.util.function.Function)
.- Returns:
- Like
Stream.flatMap(java.util.function.Function)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
flatMapToDouble
default java.util.stream.DoubleStream flatMapToDouble(IOFunction<? super T,? extends java.util.stream.DoubleStream> mapper) throws java.io.IOException
TODO Package-private for now, needs IODoubleStream? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one. It would be ideal to have only one. LikeStream.flatMapToDouble(java.util.function.Function)
.- Parameters:
mapper
- LikeStream.flatMapToDouble(java.util.function.Function)
.- Returns:
- Like
Stream.flatMapToDouble(java.util.function.Function)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
flatMapToInt
default java.util.stream.IntStream flatMapToInt(IOFunction<? super T,? extends java.util.stream.IntStream> mapper) throws java.io.IOException
TODO Package-private for now, needs IOIntStream? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one. It would be ideal to have only one. LikeStream.flatMapToInt(java.util.function.Function)
.- Parameters:
mapper
- LikeStream.flatMapToInt(java.util.function.Function)
.- Returns:
- Like
Stream.flatMapToInt(java.util.function.Function)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
flatMapToLong
default java.util.stream.LongStream flatMapToLong(IOFunction<? super T,? extends java.util.stream.LongStream> mapper) throws java.io.IOException
TODO Package-private for now, needs IOLongStream? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one. It would be ideal to have only one. LikeStream.flatMapToLong(java.util.function.Function)
.- Parameters:
mapper
- LikeStream.flatMapToLong(java.util.function.Function)
.- Returns:
- Like
Stream.flatMapToLong(java.util.function.Function)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
forAll
default void forAll(IOConsumer<T> action) throws IOExceptionList
Performs an action for each element gathering any exceptions.- Parameters:
action
- The action to apply to each element.- Throws:
IOExceptionList
- if any I/O errors occur.
-
forAll
default void forAll(IOConsumer<T> action, java.util.function.BiFunction<java.lang.Integer,java.io.IOException,java.io.IOException> exSupplier) throws IOExceptionList
Performs an action for each element gathering any exceptions.- Parameters:
action
- The action to apply to each element.exSupplier
- The exception supplier.- Throws:
IOExceptionList
- if any I/O errors occur.
-
forEach
default void forEach(IOConsumer<? super T> action) throws java.io.IOException
LikeStream.forEach(java.util.function.Consumer)
but throwsIOException
.- Parameters:
action
- LikeStream.forEach(java.util.function.Consumer)
.- Throws:
java.io.IOException
- if an I/O error occurs.
-
forEachOrdered
default void forEachOrdered(IOConsumer<? super T> action) throws java.io.IOException
LikeStream.forEachOrdered(java.util.function.Consumer)
.- Parameters:
action
- LikeStream.forEachOrdered(java.util.function.Consumer)
.- Throws:
java.io.IOException
- if an I/O error occurs.
-
limit
default IOStream<T> limit(long maxSize)
LikeStream.limit(long)
.- Parameters:
maxSize
- LikeStream.limit(long)
.- Returns:
- Like
Stream.limit(long)
.
-
map
default <R> IOStream<R> map(IOFunction<? super T,? extends R> mapper) throws java.io.IOException
LikeStream.map(java.util.function.Function)
.- Type Parameters:
R
- LikeStream.map(java.util.function.Function)
.- Parameters:
mapper
- LikeStream.map(java.util.function.Function)
.- Returns:
- Like
Stream.map(java.util.function.Function)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
mapToDouble
default java.util.stream.DoubleStream mapToDouble(java.util.function.ToDoubleFunction<? super T> mapper)
TODO Package-private for now, needs IOToDoubleFunction? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one. It would be ideal to have only one. LikeStream.mapToDouble(ToDoubleFunction)
. Package private for now.- Parameters:
mapper
- LikeStream.mapToDouble(ToDoubleFunction)
.- Returns:
- Like
Stream.mapToDouble(ToDoubleFunction)
.
-
mapToInt
default java.util.stream.IntStream mapToInt(java.util.function.ToIntFunction<? super T> mapper)
TODO Package-private for now, needs IOToIntFunction? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one. It would be ideal to have only one. LikeStream.mapToInt(ToIntFunction)
. Package private for now.- Parameters:
mapper
- LikeStream.mapToInt(ToIntFunction)
.- Returns:
- Like
Stream.mapToInt(ToIntFunction)
.
-
mapToLong
default java.util.stream.LongStream mapToLong(java.util.function.ToLongFunction<? super T> mapper)
TODO Package-private for now, needs IOToLongFunction? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one. It would be ideal to have only one. LikeStream.mapToLong(ToLongFunction)
. Package private for now.- Parameters:
mapper
- LikeStream.mapToLong(ToLongFunction)
.- Returns:
- Like
Stream.mapToLong(ToLongFunction)
.
-
max
default java.util.Optional<T> max(IOComparator<? super T> comparator) throws java.io.IOException
LikeStream.max(java.util.Comparator)
.- Parameters:
comparator
- LikeStream.max(java.util.Comparator)
.- Returns:
- Like
Stream.max(java.util.Comparator)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
min
default java.util.Optional<T> min(IOComparator<? super T> comparator) throws java.io.IOException
LikeStream.min(java.util.Comparator)
.- Parameters:
comparator
- LikeStream.min(java.util.Comparator)
.- Returns:
- Like
Stream.min(java.util.Comparator)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
noneMatch
default boolean noneMatch(IOPredicate<? super T> predicate) throws java.io.IOException
LikeStream.noneMatch(java.util.function.Predicate)
.- Parameters:
predicate
- LikeStream.noneMatch(java.util.function.Predicate)
.- Returns:
- Like
Stream.noneMatch(java.util.function.Predicate)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
peek
default IOStream<T> peek(IOConsumer<? super T> action) throws java.io.IOException
LikeStream.peek(java.util.function.Consumer)
.- Parameters:
action
- LikeStream.peek(java.util.function.Consumer)
.- Returns:
- Like
Stream.peek(java.util.function.Consumer)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
reduce
default java.util.Optional<T> reduce(IOBinaryOperator<T> accumulator) throws java.io.IOException
LikeStream.reduce(java.util.function.BinaryOperator)
.- Parameters:
accumulator
- LikeStream.reduce(java.util.function.BinaryOperator)
.- Returns:
- Like
Stream.reduce(java.util.function.BinaryOperator)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
reduce
default T reduce(T identity, IOBinaryOperator<T> accumulator) throws java.io.IOException
LikeStream.reduce(Object, java.util.function.BinaryOperator)
.- Parameters:
identity
- LikeStream.reduce(Object, java.util.function.BinaryOperator)
.accumulator
- LikeStream.reduce(Object, java.util.function.BinaryOperator)
.- Returns:
- Like
Stream.reduce(Object, java.util.function.BinaryOperator)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
reduce
default <U> U reduce(U identity, IOBiFunction<U,? super T,U> accumulator, IOBinaryOperator<U> combiner) throws java.io.IOException
LikeStream.reduce(Object, BiFunction, java.util.function.BinaryOperator)
.- Type Parameters:
U
- LikeStream.reduce(Object, BiFunction, java.util.function.BinaryOperator)
.- Parameters:
identity
- LikeStream.reduce(Object, BiFunction, java.util.function.BinaryOperator)
.accumulator
- LikeStream.reduce(Object, BiFunction, java.util.function.BinaryOperator)
.combiner
- LikeStream.reduce(Object, BiFunction, java.util.function.BinaryOperator)
.- Returns:
- Like
Stream.reduce(Object, BiFunction, java.util.function.BinaryOperator)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
skip
default IOStream<T> skip(long n)
LikeStream.skip(long)
.- Parameters:
n
- LikeStream.skip(long)
.- Returns:
- Like
Stream.skip(long)
.
-
sorted
default IOStream<T> sorted(IOComparator<? super T> comparator) throws java.io.IOException
LikeStream.sorted(java.util.Comparator)
.- Parameters:
comparator
- LikeStream.sorted(java.util.Comparator)
.- Returns:
- Like
Stream.sorted(java.util.Comparator)
. - Throws:
java.io.IOException
- if an I/O error occurs.
-
toArray
default java.lang.Object[] toArray()
LikeStream.toArray()
.- Returns:
Stream.toArray()
.
-
toArray
default <A> A[] toArray(java.util.function.IntFunction<A[]> generator)
TODO Package-private for now, needs IOIntFunction? Adding this method now and an IO version later is an issue because call sites would have to type-cast to pick one. It would be ideal to have only one. LikeStream.toArray(IntFunction)
. Package private for now.- Type Parameters:
A
- LikeStream.toArray(IntFunction)
.- Parameters:
generator
- LikeStream.toArray(IntFunction)
.- Returns:
- Like
Stream.toArray(IntFunction)
.
-
-