title: How to track size of downloaded content in java
body: <p>I have a requirement to track the size of content that user downloads from our web application (based on spring boot 2.x). Even when download wasn't successful I should write down (to database) how many data was transferred.
  So far I've found <a href="https://commons.apache.org/proper/commons-io/javadocs/api-2.5/org/apache/commons/io/output/CountingOutputStream.html" rel="nofollow noreferrer">CountingOutputStream</a> which probably should do the trick but I'm also looking for other solutions.</p>
  <p>Does anybody used <code>CountingOutputStream</code> and have some gotchas how to handle the downloads properly or did somebody implemented this with another solution?</p>