AutoCloseable
, Iterable<Result.Product>
public class ProductStreamer extends Object implements Iterable<Result.Product>, AutoCloseable
ProductStreamer
that allows you to do filtered product exports, conveniently parsed into
Result.Product
items. Every new iteration on this class will result in a new request to eSales. Note that the ProductStreamer
must be closed when done, which is most conveniently done by using a try-with-resources block as in the example below:
try(ProductStreamer productStreamer = connector.exportProducts(null,null)){ for (Product p : productStreamer){ // Do something } }
While iterating, imports will be blocked from completing on a selected eSales server. Imports will not fail but will wait for the iteration to finish. This means that if you fail to close the ProductStreamer you might block imports indefinitely!
If the iteration is interrupted by an error, an InterruptedIterationException
will be thrown. To save the whole result
in memory, you can use the toList()
convenience method.
Modifier and Type | Method | Description |
---|---|---|
void |
close() |
|
Iterator<Result.Product> |
iterator() |
Closes any previous iterator associated with this ProductStreamer and creates a new iterator.
|
List<Result.Product> |
toList() |
Iterates through all products and returns them as a list.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public Iterator<Result.Product> iterator()
iterator
in interface Iterable<Result.Product>
Result.Product
items as a list.InterruptedIterationException
- if there was an error reading the stream, or the stream could not be parsedpublic List<Result.Product> toList()
Result.Product
items as a list.InterruptedIterationException
- if the iteration was prematurely interrupted due to an error reading the stream, or
that the stream could not be parsedpublic void close()
close
in interface AutoCloseable
Copyright © 2021 Apptus Technologies AB. All rights reserved.