07-08-2009 07:57 AM
Sorry if this sounds a bit nooby
Is there a way to access the list of class resources?
Class cls = Class.forName("com.foo.Foobar.Foobar"); InputStream input = cls.getResourceAsStream("/fooSound_A.mp3");
Now, is there a way to find out all the resources in the app dynamically (I know there is a fooSound_B.mp3 there, but I want to find it, not 'remember' it) ?
In short, I would like to list all the resources of a given class.
Is it possible, or do I have to guess the names ( in case I forget them or want the user to input the string to fetch test the existance of the resource ) ?
I need this functionality for a test tool application.
07-08-2009 08:44 AM
In an article dedicated to J2ME optimization I read about good approach for handinling resources.
It is much more better to pack all resources to one file and access this file as a separate filesystem (via custom class).
Especially this approach is effective for game developers.
For instance when a game developer needs to store many bitmaps related to a game character it is possible to extract palette information from the one file and store only data blocks of all files with one copy of palette information. In most cases palette is the same for all bitmaps related to a game character.
And so on, big text resources can be packaged by zip algorithm into one resource file and accessed from the application by resource name.
In this case the application can retrieve the list of all resources.
The only name a developer needs to memorize and hardcode into the application is the name of the resource package file.
07-08-2009 08:50 AM
Thanks for pointing it out, I already use this approach (with bitmaps only, since I don't have a lot of text).
But the question again would be how to list all those packages (i.e resources)?
I don't intend to cross the border over to reverse engineering, but am just wondering if resource listing is possible.
If I know a given resource is there, just don't know its exact name... it is as if I don't know it at all? or does JVM offer me some help ?
Thanks for your input.
07-08-2009 10:02 AM
Just read this interesting thread .. As far as I know I agree with tbilisoft that there is no API to get this done..
But if there is no such resource, you will get a null from your Class.forName().getResource("resource").. You could find its existence using it..
07-08-2009 10:04 AM
07-08-2009 10:15 AM
hmmm... yes. I understand, but that's (basically) the same thing.
I am trying to 'explore' the resource set, not just to prove if a given resurce is there or not
10-16-2009 08:10 PM
I hate to dredge up such an old thread...well...not really.
I'm confronting the same issue right now. It's kind of a code efficiency/maintainability issue...I've got 20 bitmaps(not a lot) but I don't just want all the declarations that go along with creating all those Bitmaps and BitmapFields sitting around in a code file: that's material for a database.
I know this is going to sound hackish but a lot of plugin APIs call for manifest files. A manifest file (plaintext or XML) of resources might improve code efficiency at the expense of more maintenance. It's not a perfect idea and not really all that inspired/original but it would be fairly easy to implement. Somebody could even create an Eclipse plugin that auto-generates a manifest file for you and maybe even spits out a generic class for accessing the data in the manifest.