title: How to effectively parse text files with Java Stream API
body: <p>I understand how to get specific data from a file with Java 8 Streams. For example if we need to get <em>Loaded package</em>s from a file like this</p>
  
  <pre><code>2015-01-06 11:33:03 b.s.d.task [INFO] Emitting: eVentToRequestsBolt __ack_ack 
  2015-01-06 11:33:03 c.s.p.d.PackagesProvider [INFO] ===---&gt; Loaded package com.foo.bar
  2015-01-06 11:33:04 b.s.d.executor [INFO] Processing received message source: eventToManageBolt:2, stream: __ack_ack, id: {}, [-6722594615019711369 -1335723027906100557]
  2015-01-06 11:33:04 c.s.p.d.PackagesProvider [INFO] ===---&gt; Loaded package co.il.boo
  2015-01-06 11:33:04 c.s.p.d.PackagesProvider [INFO] ===---&gt; Loaded package dot.org.biz
  </code></pre>
  
  <p>we can do</p>
  
  <pre><code>List&lt;String&gt; packageList = Files.lines(Paths.get(args[1])).filter(line -&gt; line.contains("===---&gt; Loaded package"))
          .map(line -&gt; line.split(" "))
          .map(arr -&gt; arr[arr.length - 1]).collect(Collectors.toList());
  </code></pre>
  
  <p>I took (and slightly modified) the code from <a href="https://dzone.com/articles/java-8-stream-and-lambda" rel="nofollow">Parsing File Example</a>.</p>
  
  <p>But what if we also need to get all the dates (and times) for <em>Emitting:</em> events from the same log file? How we can do this within working with the same Stream?</p>
  
  <p>I can only imagine using <code>collect(groupingBy(...))</code> which groups lines with <em>Loaded packages</em> and lines with <em>Emitting:</em> before parsing and then parse each group (a map entry) separately. But that would create a map with all the raw data from log file which is very memory consuming.</p>
  
  <p>Is there a similar way to effectively extract multiple types of data from Java 8 Streams?</p>