StreamIterable - create an iterable from a Java 8 Stream
Two things:


I think you have missed the native implementation. Are you intentionally re-inventing the wheel? Streams have an iterator() method.
Note that streams cannot be reversed, so, while you can create an iterator once, from the stream, you cannot create a second iterator.... In other words, you cannot loop more than once through your iterable.


Consider reworking your class as:

public class StreamIterable&lt;T&gt; implements Iterable&lt;T&gt; {

  private final Stream&lt;T&gt; stream;

  public StreamIterable(Stream&lt;T&gt; stream) {
    this.stream = stream;
  }

  @Override
  public Iterator&lt;T&gt; iterator() {
    return stream.iterator();
  }
}


That's it, no additional code needed. You can still only iterate it once, but, you can add the above to an enhanced-for loop:

for (String v : new StreamIterable(Files.lines(...)) {
    ....
}