title: java stream custom summary statistics
body: <p>The following is a sample of a very large CSV file:</p>
  <pre><code>id, type, profit, purchaseDate, soldDate
  order1, fruit, 115.50, 1/1/2020, 20/1/2020
  order2, veg, 114.25, 7/1/2020, 7/2/2020
  order3, flowers, 113.30, 5/1/2020, 15/1/2020
  order4, fruit, 111.20, 1/1/2019, 30/1/2019
  order5, veg, 112.40, 17/1/2019,10/2/2019
  </code></pre>
  <p>I need to read this very large file and produce the following summary of statistics:</p>
  <ol>
  <li>item wise profits</li>
  <li>year with highest orders</li>
  <li>avg time between purchase and sale dates</li>
  </ol>
  <p>I can do one stat at a time.I have used commons CSV parser:</p>
  <pre><code>Reader in = new FileReader(&quot;filePath&quot;);
  Iterable&lt;CSVRecord&gt; records = CSVFormat.DEFAULT
                                         .withFirstRecordAsHeader()
                                         .withIgnoreEmptyLines(true)
                                         .withDelimiter(',')
                                         .withTrim()
                                         .parse(in);
  StreamSupport
      .stream(records.spliterator(), false)
      .collect(groupingBy(r -&gt; r.get(&quot;type&quot;),averagingDouble(r -&gt;  Double.parseDouble(r.get(&quot;profit&quot;)))));                                    
  </code></pre>
  <p>I am looking to see if we can get multiple stats using Java streaming api with a single sweep and without memory overload as this is a very large file.</p>