private long getContentLength()

in src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceMetadata.java [158:184]


    private long getContentLength(@NotNull Node node) {
        try {
            // if the node has a jcr:data property, use that property
            Property prop = NodeUtil.getPropertyOrNull(node, JCR_DATA);
            if (prop != null) {
                return JcrItemResource.getContentLength(prop);
            } else {
                // otherwise try to follow default item trail
                Item item = getPrimaryItem(node);
                while (item != null && item.isNode()) {
                    item = getPrimaryItem((Node) item);
                }
                if (item != null) {
                    final Property data = (Property) item;

                    // set the content length property as a side effect
                    // for resources which are not nt:file based and whose
                    // data is not in jcr:content/jcr:data this will lazily
                    // set the correct content length
                    return JcrItemResource.getContentLength(data);
                }
            }
        } catch (final RepositoryException re) {
            report(re);
        }
        return -1;
    }