public class Closeables extends Object
Modifier and Type | Method and Description |
---|---|
static <R> CloseableIterator<R> |
iterator(BaseStream<R,Stream<R>> stream)
Creates a closeable iterator that when closed will close the underlying stream as well
|
static <E> CloseableIterator<E> |
iterator(Iterator<? extends E> iterator)
Creates a closeable iterator from the given iterator that does nothing when close is called.
|
static <E> CloseableIterator<E> |
iterator(org.reactivestreams.Publisher<E> publisher,
int fetchSize)
Converts a
Publisher to a CloseableIterator by utilizing items fetched into an array and
refetched as they are consumed from the iterator. |
static <R> CloseableSpliterator<R> |
spliterator(BaseStream<R,Stream<R>> stream)
Creates a closeable spliterator that when closed will close the underlying stream as well
|
static <E> CloseableSpliterator<E> |
spliterator(CloseableIterator<? extends E> iterator,
long size,
int characteristics)
Takes a provided closeable iterator and wraps it appropriately so it can be used as a closeable spliterator that
will close the iterator when the spliterator is closed.
|
static <T> CloseableSpliterator<T> |
spliterator(Spliterator<T> spliterator)
Creates a closeable spliterator from the given spliterator that does nothing when close is called.
|
static <E> Stream<E> |
stream(CloseableIterator<E> iterator,
boolean parallel,
long size,
int characteristics)
Creates a stream that when closed will also close the underlying iterator
|
static <E> Stream<E> |
stream(CloseableSpliterator<E> spliterator,
boolean parallel)
Creates a stream that when closed will also close the underlying spliterator
|
public static <E> CloseableSpliterator<E> spliterator(CloseableIterator<? extends E> iterator, long size, int characteristics)
E
- The type that is the same between the iterator and spliteratoriterator
- The closeable iterator to change to a spliteratorsize
- The approximate size of the iterator. If no size is known Long.MAX_VALUE
should be passedcharacteristics
- The characteristics of the given spliterator as defined on the Spliterator
interfacepublic static <T> CloseableSpliterator<T> spliterator(Spliterator<T> spliterator)
T
- The type of the spliteratorsspliterator
- The spliterator to wrap to allow it to become a closeable spliterator.public static <R> CloseableSpliterator<R> spliterator(BaseStream<R,Stream<R>> stream)
R
- The type of the streamstream
- The stream to change into a closeable spliteratorpublic static <R> CloseableIterator<R> iterator(BaseStream<R,Stream<R>> stream)
R
- The type of the streamstream
- The stream to change into a closeable iteratorpublic static <E> CloseableIterator<E> iterator(Iterator<? extends E> iterator)
E
- The type of the iteratorsiterator
- The iterator to wrap to allow it to become a closeable iteratorpublic static <E> Stream<E> stream(CloseableSpliterator<E> spliterator, boolean parallel)
E
- the type of the streamspliterator
- spliterator to back the stream and subsequently closeparallel
- whether or not the returned stream is parallel or notpublic static <E> Stream<E> stream(CloseableIterator<E> iterator, boolean parallel, long size, int characteristics)
E
- the type of the streamiterator
- iterator to back the stream and subsequently closeparallel
- whether or not the returned stream is parallel or notsize
- the size of the iterator if known, otherwise Long.MAX_VALUE
should be passed.characteristics
- the characteristics of the iterator to be usedpublic static <E> CloseableIterator<E> iterator(org.reactivestreams.Publisher<E> publisher, int fetchSize)
Publisher
to a CloseableIterator
by utilizing items fetched into an array and
refetched as they are consumed from the iterator. The iterator when closed will also close the underlying
Subscription
when subscribed to the publisher.E
- value typepublisher
- the publisher to convertfetchSize
- how many entries to hold in memory at once in preparation for the iterators consumptionCopyright © 2021 JBoss by Red Hat. All rights reserved.