title: how converte large XML file to stream-like-java8 of object
body: <p>Hy,
  I have a (very)large XML file (100GB) with a list of foo, I want to convert-it into a stream like they where introduce into java 8  of object:</p>
  
  <p>Any idea of lib or code sample?</p>
  
  <p>at the beginning:</p>
  
  <pre><code>&lt;foos&gt; 
    &lt;foo&gt;...&lt;/foo&gt;
    &lt;foo&gt;...&lt;/foo&gt;
  &lt;/foos&gt;
  </code></pre>
  
  <p>at the end:</p>
  
  <pre><code>Stream&lt;Foo&gt;  foosStream = ????("foo.xml")
  streamFoos.forEach(foo-&gt;foo.doFooStuffs());
  </code></pre>
  
  <p>Edit:
  @Pierre Thank-you, here is the implementation of your solution:</p>
  
  <pre><code>  try {
              XMLEventReader reader = XMLInputFactory.newInstance().
                      createXMLEventReader(stream);
              final Unmarshaller unmarshaller = JAXBContext.newInstance(XXXXX.class).createUnmarshaller();
  
              Iterator&lt;XXXXX&gt; it = new XmlIterator&lt;&gt;(reader, unmarshaller, "xxxxxx");
              return StreamSupport.stream(Spliterators.spliteratorUnknownSize(it, Spliterator.ORDERED), false);
          } catch (XMLStreamException e1) {
              logger.error("XMLStreamException", e1);
          } catch (JAXBException e) {
              logger.error("JAXBException", e);
          }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public class XmlIterator&lt;T&gt; implements Iterator&lt;T&gt; {
  
      private final Logger logger = LoggerFactory.getLogger(this.getClass());
  
      XMLEventReader reader;
  
      XMLEvent event;
  
      Unmarshaller unmarshaller;
      String name;
  
      public XmlIterator(XMLEventReader reader, Unmarshaller unmarshaller, String name) {
          this.reader = reader;
          this.unmarshaller = unmarshaller;
          this.name = name;
          try {
              reader.next();
              this.event = reader.peek();
          } catch (XMLStreamException e) {
              logger.error("", e);
              event = null;
          }
      }
  
      @Override
      public boolean hasNext() {
          try {
              while (event != null &amp;&amp; !(event.isStartElement() &amp;&amp; name.equals(event.asStartElement().getName().getLocalPart()))) {
                  Object a = reader.next();
                  event = reader.peek();
              }
              return event != null;
  
          } catch (XMLStreamException e) {
              logger.error("", e);
              event = null;
          }
          return event != null;
      }
  
      @Override
      public T next() {
          try {
              T next = ((JAXBElement&lt;T&gt;) unmarshaller.unmarshal(reader)).getValue();
              event = reader.peek();
              return next;
          } catch (JAXBException e) {
              logger.error("error during unmarshalling ", e);
              return null;
          } catch (XMLStreamException e) {
              logger.error("error during stream ", e);
              return null;
          }
      }
  }
  </code></pre>