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>>
    Like Stream but throws IOException.
    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)
      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​(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)
      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 java.util.Optional<T> findAny()
      Like Stream.findAny().
      default java.util.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 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)
      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 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)
      Like Stream.max(java.util.Comparator).
      default java.util.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​(java.lang.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 java.util.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 java.lang.Object[] toArray()
      Like Stream.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.
    • 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 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​(java.lang.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 java.io.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:
        java.io.IOException - if an I/O error occurs.
      • anyMatch

        default boolean anyMatch​(IOPredicate<? super T> predicate)
                          throws java.io.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:
        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. 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 java.io.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:
        java.io.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 java.io.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:
        java.io.IOException - if an I/O error occurs.
      • findAny

        default java.util.Optional<T> findAny()
        Like Stream.findAny().
        Returns:
        Like Stream.findAny().
      • findFirst

        default java.util.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 java.io.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:
        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. 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:
        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. 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:
        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. 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:
        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
        Like Stream.forEach(java.util.function.Consumer) but throws IOException.
        Parameters:
        action - Like Stream.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
        Like Stream.forEachOrdered(java.util.function.Consumer).
        Parameters:
        action - Like Stream.forEachOrdered(java.util.function.Consumer).
        Throws:
        java.io.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 java.io.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:
        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. Like Stream.mapToDouble(ToDoubleFunction). Package private for now.
        Parameters:
        mapper - Like Stream.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. Like Stream.mapToInt(ToIntFunction). Package private for now.
        Parameters:
        mapper - Like Stream.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. Like Stream.mapToLong(ToLongFunction). Package private for now.
        Parameters:
        mapper - Like Stream.mapToLong(ToLongFunction).
        Returns:
        Like Stream.mapToLong(ToLongFunction).
      • max

        default java.util.Optional<T> max​(IOComparator<? super T> comparator)
                                   throws java.io.IOException
        Like Stream.max(java.util.Comparator).
        Parameters:
        comparator - Like Stream.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
        Like Stream.min(java.util.Comparator).
        Parameters:
        comparator - Like Stream.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
        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:
        java.io.IOException - if an I/O error occurs.
      • peek

        default IOStream<T> peek​(IOConsumer<? super T> action)
                          throws java.io.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:
        java.io.IOException - if an I/O error occurs.
      • reduce

        default java.util.Optional<T> reduce​(IOBinaryOperator<T> accumulator)
                                      throws java.io.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:
        java.io.IOException - if an I/O error occurs.
      • reduce

        default T reduce​(T identity,
                         IOBinaryOperator<T> accumulator)
                  throws java.io.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:
        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
        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:
        java.io.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 java.io.IOException
        Like Stream.sorted(java.util.Comparator).
        Parameters:
        comparator - Like Stream.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()
        Like Stream.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. 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).