@Override
    public long contentLength() throws IOException {
        InputStream is = getInputStream();
        try {
            long size = 0;
            byte[] buf = new byte[256];
            int read;
            while ((read = is.read(buf)) != -1) {
                size += read;
            }
            return size;
        } finally {
            try {
                is.close();
            } catch (IOException ex) {
                Logger logger = LogManager.getLogger(getClass());
                if (logger.isDebugEnabled()) {
                    logger.debug("Could not close content-length InputStream for {}", getDescription(), ex);
                }
            }
        }
    }
This method reads the entire InputStream to determine the content length.
<p>For a custom subclass of {@code InputStreamResource}, we strongly
recommend overriding this method with a more optimal implementation, e.g.
checking File length, or possibly simply returning -1 if the stream can
only be read once.

see #getInputStream()
analyzer/src/main/java/nl/basjes/parse/useragent/utils/springframework/core/io/AbstractResource.java