ICJC said:
Is there any way to find the length of a resource (as retrieved by
Class.getResourceAsStream())?
Since getResourceAsStream() returns an InputStream, your question
becomes "Is there any way to find the length of an InputStream?" The
answer to this question is no, as an InputStream need not have a well
defined length.
This seems like an obvious piece of
functionality, but I can't find any API call that does it.
No, it's not obvious at all. You are incorporating an assumption that a
"resource" is necessarilly a fixed-length local file, or part of one.
That may frequently or even typically be the case, but it is in no way
required. If you are willing to make that assumption, however, then you
can try parsing the URL obtained via Class.getResource() and analyzing
the specified resource appropriately. You need to be prepared to handle
both whole files and zip / jar entries, at the very least. (Actually,
I'm not sure what the URL for a file in a jar or zip looks like, come to
think of it.)
John Bollinger
(e-mail address removed)