Determine CLASSPATH resource file size

Viewed 1750

The Question

Is it possible to determine the size of an arbitrary classpath resource? Here's a hypothetical build below (full disclosure: I'm not google). In this case I want to obtain the size of icon.png.

  • src
    • com
      • google
        • App.java
        • icon.png
        • app.json

I know I can create a Path/File from this resource using it's URI (from the classpath URL) and get it's size.

Files.size(Path.get(ClassLoader.getSystemResource(iconPath).toURI()))

But it's my understanding this won't work when I deploy this in a JAR or use an AOT compilation tool such as Excelsior JET.

Note: in both these scenarios (Excelsior or the JAR) I can load icon.png just fine.

Just to clarify. My goal is not to obtain a file from a given resource! The goal is to obtain the size of the resource. The above is just an example of a broken solution.

The Reason

To obtain accurate progress information while loading many resources during run time.

Equate the current progress from the current amount of bytes processed to the total amount of bytes to be processed.

TL;DR I just need someone to tell me that this is not possible so I can come up with a different solution.

1 Answers
Related