Java 8 Streams Count all Keys
<p>I have a file that contains data in the form of JSON format. I am reading it line by line and every line has 1 JSON record so the format is really not an issue. Below is an example line:</p>

<pre><code>{"url": "http://ldrlongdistancerider.com/bikers_rights_motorcycle/rightsriders0163.php", "timestamp": 1257072412, "tags": ["nscensorship", "cloudmark", "network", "solutions", "content", "based", "spam", "signatures"]}
</code></pre>

<p>What I need to do is count all the duplicate URLs and print it like:</p>

<pre><code> http://ldrlongdistancerider.com/bikers_rights_motorcycle/rightsriders0163.php"  1
</code></pre>

<p>How can I achieve this using streams? By the way, I need to filter the records based on the timestamp. So if someone passed a range of dates, I would have to count the URLs falling in that range. I have done most of it but this counting part is confusing to me.</p>

<p>Here is what I have done so far:</p>

<pre><code>for (Path filePath : files) {
        try {
            Files.lines(Paths.get(filePath.toUri()))
                 .filter(s -&gt; Link.parse(s).timestamp() &gt; startSeconds)
                 .filter(s -&gt; Link.parse(s).timestamp() &lt; stopSeconds)
                 .forEach(s -&gt; countMap.put(Link.parse(s).url(), 1));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
</code></pre>

<p>countMap is HashMap of String, Integer</p>