@Override
    public long contentLength() throws IOException {
        InputStream is = this.getInputStream();
        Assert.state(is != null, "resource input stream must not be null");
        try {
            long size = 0;
            byte[] buf = new byte[255];
            int read;
            while ((read = is.read(buf)) != -1) {
                size += read;
            }
            return size;
        } finally {
            try {
                is.close();
            } catch (IOException ex) {
            }
        }
    }
This implementation reads the entire InputStream to calculate the
content length. Subclasses will almost always be able to provide
a more optimal version of this, e.g. checking a File length.

@throws IllegalStateException if {@link #getInputStream()} returns null.
@see #getInputStream()
src/main/java/spark/resource/AbstractResource.java