| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
package org.apache.commons.io.function; |
| 19 |
|
| 20 |
import java.io.IOException; |
| 21 |
import java.util.function.BiFunction; |
| 22 |
import java.util.stream.Stream; |
| 23 |
import java.util.stream.StreamSupport; |
| 24 |
|
| 25 |
import org.apache.commons.io.IOExceptionList; |
| 26 |
import org.apache.commons.io.IOIndexedException; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
final class IOStreams { |
| 32 |
|
| 33 |
static final Object NONE = new Object(); |
| 34 |
|
| 35 |
static <T> void forAll(final Stream<T> stream, final IOConsumer<T> action) throws IOExceptionList { |
| 36 |
forAll(stream, action, (i, e) -> e); |
| 37 |
} |
| 38 |
|
| 39 |
@SuppressWarnings("resource") |
| 40 |
static <T> void forAll(final Stream<T> stream, final IOConsumer<T> action, final BiFunction<Integer, IOException, IOException> exSupplier) |
| 41 |
throws IOExceptionList { |
| 42 |
IOStream.adapt(stream).forAll(action, IOIndexedException::new); |
| 43 |
} |
| 44 |
|
| 45 |
@SuppressWarnings("unused") |
| 46 |
static <T> void forEach(final Stream<T> stream, final IOConsumer<T> action) throws IOException { |
| 47 |
final IOConsumer<T> actualAction = toIOConsumer(action); |
| 48 |
of(stream).forEach(e -> Erase.accept(actualAction, e)); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
static <T> Stream<T> of(final Iterable<T> values) { |
| 61 |
return values == null ? Stream.empty() : StreamSupport.stream(values.spliterator(), false); |
| 62 |
} |
| 63 |
|
| 64 |
static <T> Stream<T> of(final Stream<T> stream) { |
| 65 |
return stream == null ? Stream.empty() : stream; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
@SafeVarargs |
| 78 |
static <T> Stream<T> of(final T... values) { |
| 79 |
return values == null ? Stream.empty() : Stream.of(values); |
| 80 |
} |
| 81 |
|
| 82 |
static <T> IOConsumer<T> toIOConsumer(final IOConsumer<T> action) { |
| 83 |
return action != null ? action : IOConsumer.noop(); |
| 84 |
} |
| 85 |
|
| 86 |
private IOStreams() { |
| 87 |
|
| 88 |
} |
| 89 |
} |