You can use com.google.common.base.AbstractIterator