Package org.eclipse.rdf4j.federated.evaluation.iterator

## Class ConsumingIteration

- java.lang.Object
- - org.eclipse.rdf4j.federated.evaluation.iterator.ConsumingIteration

- All Implemented Interfaces:
    `AutoCloseable`, `CloseableIteration<BindingSet,​QueryEvaluationException>`, `Iteration<BindingSet,​QueryEvaluationException>`

      public class ConsumingIteration
      extends Object
      implements CloseableIteration<BindingSet,​QueryEvaluationException>

  A specialized `CloseableIteration` that consumes part (or the entire input iteration if it fits into the buffer) and keeps data for further processing in memory. If the buffer is full, the remaining items will be read from the iteration lazily. This implementation can be used to avoid blocking behavior in HTTP connection streams, i.e. to process results in memory and close the underlying HTTP stream.
  Author:
    Andreas Schwarte

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ConsumingIteration​(CloseableIteration<BindingSet,​QueryEvaluationException> iter, int max)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `close()` | Closes this iteration, freeing any resources that it is holding.
    `boolean` | `hasNext()` | Returns true if the iteration has more elements.
    `BindingSet` | `next()` | Returns the next element in the iteration.
    `void` | `remove()` | Removes from the underlying collection the last element returned by the iteration (optional operation).

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.eclipse.rdf4j.common.iteration.Iteration

      `stream`

- - ### Constructor Detail

    - #### ConsumingIteration

          public ConsumingIteration​(CloseableIteration<BindingSet,​QueryEvaluationException> iter,
                                    int max)
                             throws QueryEvaluationException

      Parameters:
        `iter` - iteration to be consumed
        `max` - the number of results to be consumed.
      Throws:
        `QueryEvaluationException`

  - ### Method Detail

    - #### hasNext

          public boolean hasNext()
                          throws QueryEvaluationException

      Description copied from interface: `Iteration`
      Returns true if the iteration has more elements. (In other words, returns true if `Iteration.next()` would return an element rather than throwing a NoSuchElementException.)
      Specified by:
        `hasNext` in interface `Iteration<BindingSet,​QueryEvaluationException>`
      Returns:
        true if the iteration has more elements.
      Throws:
        `QueryEvaluationException`

    - #### next

          public BindingSet next()
                          throws QueryEvaluationException

      Description copied from interface: `Iteration`
      Returns the next element in the iteration.
      Specified by:
        `next` in interface `Iteration<BindingSet,​QueryEvaluationException>`
      Returns:
        the next element in the iteration.
      Throws:
        `QueryEvaluationException`

    - #### remove

          public void remove()
                      throws QueryEvaluationException

      Description copied from interface: `Iteration`
      Removes from the underlying collection the last element returned by the iteration (optional operation). This method can be called only once per call to next.
      Specified by:
        `remove` in interface `Iteration<BindingSet,​QueryEvaluationException>`
      Throws:
        `QueryEvaluationException`

    - #### close

          public void close()
                     throws QueryEvaluationException

      Description copied from interface: `CloseableIteration`
      Closes this iteration, freeing any resources that it is holding. If the iteration has already been closed then invoking this method has no effect.
      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in interface `CloseableIteration<BindingSet,​QueryEvaluationException>`
      Throws:
        `QueryEvaluationException`