title: How to push data into Java stream regularly?
body: <p>Normally one should get data from a database using a stream and then send it to Apache POI using a stream, etc. I mean, data should be in stream format from start to end. However my database codes are not written as stream and they have complicated sources from various different types from databases. Thus I need to query my data source like this <code>getData(int page, int perPage)</code>. And then I want to forward the results to the stream. Like this:</p>
  
  <pre><code>for(int i = 0; i &lt; 5000; i++) {
      stream.add(getData(i, 10000));
  }
  </code></pre>
  
  <p>So my question is how can I push data into the stream on the fly without using too much RAM?</p>