org.springframework.data.util

## Interface CloseableIterator<T>

Type Parameters:
  `T` -

All Superinterfaces:
  AutoCloseable, Closeable, Iterator<T>

    public interface CloseableIterator<T>
    extends Iterator<T>, Closeable

A `CloseableIterator` serves as a bridging data structure for the underlying data store specific results that can be wrapped in a Java 8 `java.util.stream.Stream`. This allows implementations to clean up any resources they need to keep open to iterate over elements.

Since:
  1.10
Author:
  Thomas Darimont, Mark Paluch

### Method Summary

All Methods Instance Methods Abstract Methods Default Methods
`void` `close()`
`default Spliterator<T>` `spliterator()` Create a `Spliterator` over the elements provided by this `Iterator`.
`default Stream<T>` `stream()` Return a sequential `Stream` with this `Iterator` as its source.

### Methods inherited from interface java.util.Iterator

`forEachRemaining, hasNext, next, remove`

### Method Detail

#### close

    void close()

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`

#### spliterator

    default Spliterator<T> spliterator()

Create a `Spliterator` over the elements provided by this `Iterator`. Implementations should document characteristic values reported by the spliterator. Such characteristic values are not required to be reported if the spliterator reports `Spliterator.SIZED` and this collection contains no elements.

The default implementation should be overridden by subclasses that can return a more efficient spliterator. To preserve expected laziness behavior for the `stream()` method, spliterators should either have the characteristic of `IMMUTABLE` or `CONCURRENT`, or be late-binding.

Returns:
  a `Spliterator` over the elements in this `Iterator`.
Since:
  2.4

#### stream

    default Stream<T> stream()

Return a sequential `Stream` with this `Iterator` as its source. The resulting stream calls `#clone()` when `closed`. The resulting `Stream` must be closed after use, it can be declared as a resource in a `try`-with-resources statement.

This method should be overridden when the `spliterator()` method cannot return a spliterator that is `IMMUTABLE`, `CONCURRENT`, or late-binding. (See `spliterator()` for details.)

Returns:
  a sequential `Stream` over the elements in this `Iterator`.
Since:
  2.4