Package org.apache.commons.io.function

# Interface IOStream<T>

Type Parameters:
  `T` - the type of the stream elements.

All Superinterfaces:
  `AutoCloseable`, `Closeable`, `IOBaseStream<T,IOStream<T>,Stream<T>>`

public interface IOStream<T> extends IOBaseStream<T,IOStream<T>,Stream<T>>
Like `Stream` but throws `IOException`.

Since:
  2.12.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <T> IOStream<T>`
  `adapt(Stream<T> stream)`
  Constructs a new IOStream for the given Stream.
  `default boolean`
  `allMatch(IOPredicate<? super T> predicate)`
  Like `Stream.allMatch(java.util.function.Predicate)` but throws `IOException`.
  `default boolean`
  `anyMatch(IOPredicate<? super T> predicate)`
  Like `Stream.anyMatch(java.util.function.Predicate)` but throws `IOException`.
  `default <R, A> R`
  `collect(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)`
  Like `Stream.collect(java.util.function.Supplier, java.util.function.BiConsumer, java.util.function.BiConsumer)`.
  `default long`
  `count()`
  Like `Stream.count()`.
  `default IOStream<T>`
  `distinct()`
  Like `Stream.distinct()`.
  `static <T> IOStream<T>`
  `empty()`
  This class' version of `Stream.empty()`.
  `default IOStream<T>`
  `filter(IOPredicate<? super T> predicate)`
  Like `Stream.filter(java.util.function.Predicate)`.
  `default Optional<T>`
  `findAny()`
  Like `Stream.findAny()`.
  `default Optional<T>`
  `findFirst()`
  Like `Stream.findFirst()`.
  `default <R> IOStream<R>`
  `flatMap(IOFunction<? super T,? extends IOStream<? extends R>> mapper)`
  Like `Stream.flatMap(java.util.function.Function)`.
  `default DoubleStream`
  `flatMapToDouble(IOFunction<? super T,? extends 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 IntStream`
  `flatMapToInt(IOFunction<? super T,? extends 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 LongStream`
  `flatMapToLong(IOFunction<? super T,? extends 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, BiFunction<Integer,IOException,IOException> exSupplier)`
  Performs an action for each element gathering any exceptions.
  `default void`
  `forEach(IOConsumer<? super T> action)`
  Like `Stream.forEach(java.util.function.Consumer)` but throws `IOException`.
  `default void`
  `forEachOrdered(IOConsumer<? super T> action)`
  Like `Stream.forEachOrdered(java.util.function.Consumer)`.
  `static <T> IOStream<T>`
  `iterate(T seed, IOUnaryOperator<T> f)`
  Like `Stream.iterate(Object, UnaryOperator)` but for IO.
  `default IOStream<T>`
  `limit(long maxSize)`
  Like `Stream.limit(long)`.
  `default <R> IOStream<R>`
  `map(IOFunction<? super T,? extends R> mapper)`
  Like `Stream.map(java.util.function.Function)`.
  `default DoubleStream`
  `mapToDouble(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 IntStream`
  `mapToInt(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 LongStream`
  `mapToLong(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 Optional<T>`
  `max(IOComparator<? super T> comparator)`
  Like `Stream.max(java.util.Comparator)`.
  `default Optional<T>`
  `min(IOComparator<? super T> comparator)`
  Like `Stream.min(java.util.Comparator)`.
  `default boolean`
  `noneMatch(IOPredicate<? super T> predicate)`
  Like `Stream.noneMatch(java.util.function.Predicate)`.
  `static <T> IOStream<T>`
  `of(Iterable<T> values)`
  Null-safe version of `StreamSupport.stream(java.util.Spliterator, boolean)`.
  `static <T> IOStream<T>`
  `of(T t)`
  Returns a sequential `IOStreamImpl` containing a single element.
  `static <T> IOStream<T>`
  `of(T... values)`
  Null-safe version of `Stream.of(Object[])` for an IO stream.
  `default IOStream<T>`
  `peek(IOConsumer<? super T> action)`
  Like `Stream.peek(java.util.function.Consumer)`.
  `default Optional<T>`
  `reduce(IOBinaryOperator<T> accumulator)`
  Like `Stream.reduce(java.util.function.BinaryOperator)`.
  `default T`
  `reduce(T identity, IOBinaryOperator<T> accumulator)`
  Like `Stream.reduce(Object, java.util.function.BinaryOperator)`.
  `default <U> U`
  `reduce(U identity, IOBiFunction<U,? super T,U> accumulator, IOBinaryOperator<U> combiner)`
  Like `Stream.reduce(Object, BiFunction, java.util.function.BinaryOperator)`.
  `default IOStream<T>`
  `skip(long n)`
  Like `Stream.skip(long)`.
  `default IOStream<T>`
  `sorted()`
  Like `Stream.sorted()`.
  `default IOStream<T>`
  `sorted(IOComparator<? super T> comparator)`
  Like `Stream.sorted(java.util.Comparator)`.
  `default Object[]`
  `toArray()`
  Like `Stream.toArray()`.
  `default <A> A[]`
  `toArray(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 Details

  - ### adapt

    static <T> IOStream<T> adapt(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 of `Stream.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)
    Like `Stream.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(Iterable<T> values)
    Null-safe version of `StreamSupport.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 be `null`.
    Returns:
      the new stream on `values` or `Stream.empty()`.

  - ### of

    @SafeVarargs static <T> IOStream<T> of(T... values)
    Null-safe version of `Stream.of(Object[])` for an IO stream.
    Type Parameters:
      `T` - the type of stream elements.
    Parameters:
      `values` - the elements of the new stream, may be `null`.
    Returns:
      the new stream on `values` or `Stream.empty()`.

  - ### of

    static <T> IOStream<T> of(T t)
    Returns a sequential `IOStreamImpl` 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 IOException
    Like `Stream.allMatch(java.util.function.Predicate)` but throws `IOException`.
    Parameters:
      `predicate` - `Stream.allMatch(java.util.function.Predicate)`.
    Returns:
      Like `Stream.allMatch(java.util.function.Predicate)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### anyMatch

    default boolean anyMatch(IOPredicate<? super T> predicate) throws IOException
    Like `Stream.anyMatch(java.util.function.Predicate)` but throws `IOException`.
    Parameters:
      `predicate` - `Stream.anyMatch(java.util.function.Predicate)`.
    Returns:
      Like `Stream.anyMatch(java.util.function.Predicate)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### collect

    default <R, A> R collect(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. Like `Stream.collect(Collector)`. Package private for now.
    Type Parameters:
      `R` - Like `Stream.collect(Collector)`.
      `A` - Like `Stream.collect(Collector)`.
    Parameters:
      `collector` - Like `Stream.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 IOException
    Like `Stream.collect(java.util.function.Supplier, java.util.function.BiConsumer, java.util.function.BiConsumer)`.
    Type Parameters:
      `R` - Like `Stream.collect(java.util.function.Supplier, java.util.function.BiConsumer, java.util.function.BiConsumer)`.
    Parameters:
      `supplier` - Like `Stream.collect(java.util.function.Supplier, java.util.function.BiConsumer, java.util.function.BiConsumer)`.
      `accumulator` - Like `Stream.collect(java.util.function.Supplier, java.util.function.BiConsumer, java.util.function.BiConsumer)`.
      `combiner` - Like `Stream.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:
      `IOException` - if an I/O error occurs.

  - ### count

    default long count()
    Like `Stream.count()`.
    Returns:
      Like `Stream.count()`.

  - ### distinct

    default IOStream<T> distinct()
    Like `Stream.distinct()`.
    Returns:
      Like `Stream.distinct()`.

  - ### filter

    default IOStream<T> filter(IOPredicate<? super T> predicate) throws IOException
    Like `Stream.filter(java.util.function.Predicate)`.
    Parameters:
      `predicate` - Like `Stream.filter(java.util.function.Predicate)`.
    Returns:
      Like `Stream.filter(java.util.function.Predicate)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### findAny

    default Optional<T> findAny()
    Like `Stream.findAny()`.
    Returns:
      Like `Stream.findAny()`.

  - ### findFirst

    default Optional<T> findFirst()
    Like `Stream.findFirst()`.
    Returns:
      Like `Stream.findFirst()`.

  - ### flatMap

    default <R> IOStream<R> flatMap(IOFunction<? super T,? extends IOStream<? extends R>> mapper) throws IOException
    Like `Stream.flatMap(java.util.function.Function)`.
    Type Parameters:
      `R` - Like `Stream.flatMap(java.util.function.Function)`.
    Parameters:
      `mapper` - Like `Stream.flatMap(java.util.function.Function)`.
    Returns:
      Like `Stream.flatMap(java.util.function.Function)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### flatMapToDouble

    default DoubleStream flatMapToDouble(IOFunction<? super T,? extends DoubleStream> mapper) throws 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. Like `Stream.flatMapToDouble(java.util.function.Function)`.
    Parameters:
      `mapper` - Like `Stream.flatMapToDouble(java.util.function.Function)`.
    Returns:
      Like `Stream.flatMapToDouble(java.util.function.Function)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### flatMapToInt

    default IntStream flatMapToInt(IOFunction<? super T,? extends IntStream> mapper) throws 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. Like `Stream.flatMapToInt(java.util.function.Function)`.
    Parameters:
      `mapper` - Like `Stream.flatMapToInt(java.util.function.Function)`.
    Returns:
      Like `Stream.flatMapToInt(java.util.function.Function)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### flatMapToLong

    default LongStream flatMapToLong(IOFunction<? super T,? extends LongStream> mapper) throws 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. Like `Stream.flatMapToLong(java.util.function.Function)`.
    Parameters:
      `mapper` - Like `Stream.flatMapToLong(java.util.function.Function)`.
    Returns:
      Like `Stream.flatMapToLong(java.util.function.Function)`.
    Throws:
      `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, BiFunction<Integer,IOException,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 IOException
    Like `Stream.forEach(java.util.function.Consumer)` but throws `IOException`.
    Parameters:
      `action` - Like `Stream.forEach(java.util.function.Consumer)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### forEachOrdered

    default void forEachOrdered(IOConsumer<? super T> action) throws IOException
    Like `Stream.forEachOrdered(java.util.function.Consumer)`.
    Parameters:
      `action` - Like `Stream.forEachOrdered(java.util.function.Consumer)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### limit

    default IOStream<T> limit(long maxSize)
    Like `Stream.limit(long)`.
    Parameters:
      `maxSize` - Like `Stream.limit(long)`.
    Returns:
      Like `Stream.limit(long)`.

  - ### map

    default <R> IOStream<R> map(IOFunction<? super T,? extends R> mapper) throws IOException
    Like `Stream.map(java.util.function.Function)`.
    Type Parameters:
      `R` - Like `Stream.map(java.util.function.Function)`.
    Parameters:
      `mapper` - Like `Stream.map(java.util.function.Function)`.
    Returns:
      Like `Stream.map(java.util.function.Function)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### mapToDouble

    default DoubleStream mapToDouble(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. Like `Stream.mapToDouble(ToDoubleFunction)`. Package private for now.
    Parameters:
      `mapper` - Like `Stream.mapToDouble(ToDoubleFunction)`.
    Returns:
      Like `Stream.mapToDouble(ToDoubleFunction)`.

  - ### mapToInt

    default IntStream mapToInt(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. Like `Stream.mapToInt(ToIntFunction)`. Package private for now.
    Parameters:
      `mapper` - Like `Stream.mapToInt(ToIntFunction)`.
    Returns:
      Like `Stream.mapToInt(ToIntFunction)`.

  - ### mapToLong

    default LongStream mapToLong(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. Like `Stream.mapToLong(ToLongFunction)`. Package private for now.
    Parameters:
      `mapper` - Like `Stream.mapToLong(ToLongFunction)`.
    Returns:
      Like `Stream.mapToLong(ToLongFunction)`.

  - ### max

    default Optional<T> max(IOComparator<? super T> comparator) throws IOException
    Like `Stream.max(java.util.Comparator)`.
    Parameters:
      `comparator` - Like `Stream.max(java.util.Comparator)`.
    Returns:
      Like `Stream.max(java.util.Comparator)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### min

    default Optional<T> min(IOComparator<? super T> comparator) throws IOException
    Like `Stream.min(java.util.Comparator)`.
    Parameters:
      `comparator` - Like `Stream.min(java.util.Comparator)`.
    Returns:
      Like `Stream.min(java.util.Comparator)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### noneMatch

    default boolean noneMatch(IOPredicate<? super T> predicate) throws IOException
    Like `Stream.noneMatch(java.util.function.Predicate)`.
    Parameters:
      `predicate` - Like `Stream.noneMatch(java.util.function.Predicate)`.
    Returns:
      Like `Stream.noneMatch(java.util.function.Predicate)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### peek

    default IOStream<T> peek(IOConsumer<? super T> action) throws IOException
    Like `Stream.peek(java.util.function.Consumer)`.
    Parameters:
      `action` - Like `Stream.peek(java.util.function.Consumer)`.
    Returns:
      Like `Stream.peek(java.util.function.Consumer)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### reduce

    default Optional<T> reduce(IOBinaryOperator<T> accumulator) throws IOException
    Like `Stream.reduce(java.util.function.BinaryOperator)`.
    Parameters:
      `accumulator` - Like `Stream.reduce(java.util.function.BinaryOperator)`.
    Returns:
      Like `Stream.reduce(java.util.function.BinaryOperator)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### reduce

    default T reduce(T identity, IOBinaryOperator<T> accumulator) throws IOException
    Like `Stream.reduce(Object, java.util.function.BinaryOperator)`.
    Parameters:
      `identity` - Like `Stream.reduce(Object, java.util.function.BinaryOperator)`.
      `accumulator` - Like `Stream.reduce(Object, java.util.function.BinaryOperator)`.
    Returns:
      Like `Stream.reduce(Object, java.util.function.BinaryOperator)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### reduce

    default <U> U reduce(U identity, IOBiFunction<U,? super T,U> accumulator, IOBinaryOperator<U> combiner) throws IOException
    Like `Stream.reduce(Object, BiFunction, java.util.function.BinaryOperator)`.
    Type Parameters:
      `U` - Like `Stream.reduce(Object, BiFunction, java.util.function.BinaryOperator)`.
    Parameters:
      `identity` - Like `Stream.reduce(Object, BiFunction, java.util.function.BinaryOperator)`.
      `accumulator` - Like `Stream.reduce(Object, BiFunction, java.util.function.BinaryOperator)`.
      `combiner` - Like `Stream.reduce(Object, BiFunction, java.util.function.BinaryOperator)`.
    Returns:
      Like `Stream.reduce(Object, BiFunction, java.util.function.BinaryOperator)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### skip

    default IOStream<T> skip(long n)
    Like `Stream.skip(long)`.
    Parameters:
      `n` - Like `Stream.skip(long)`.
    Returns:
      Like `Stream.skip(long)`.

  - ### sorted

    default IOStream<T> sorted()
    Like `Stream.sorted()`.
    Returns:
      Like `Stream.sorted()`.

  - ### sorted

    default IOStream<T> sorted(IOComparator<? super T> comparator) throws IOException
    Like `Stream.sorted(java.util.Comparator)`.
    Parameters:
      `comparator` - Like `Stream.sorted(java.util.Comparator)`.
    Returns:
      Like `Stream.sorted(java.util.Comparator)`.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### toArray

    default Object[] toArray()
    Like `Stream.toArray()`.
    Returns:
      `Stream.toArray()`.

  - ### toArray

    default <A> A[] toArray(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. Like `Stream.toArray(IntFunction)`. Package private for now.
    Type Parameters:
      `A` - Like `Stream.toArray(IntFunction)`.
    Parameters:
      `generator` - Like `Stream.toArray(IntFunction)`.
    Returns:
      Like `Stream.toArray(IntFunction)`.