Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Class resources list

Sorry if this sounds a bit nooby Smiley Wink

 

Is there a way to access the list of class resources?

 

For instance:

 

  Currently implemented:

 

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 Smiley Happy 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.

 

Thanks all!

 



"Listen carefully, I shall say this only once"
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Class resources list

No, it does not sound as noobie, it is very interesting question.

 

I would like to know this too Smiley Happy

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Class resources list

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.

Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: Class resources list

Thanks for pointing it out, I already use this approach Smiley Happy (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.



"Listen carefully, I shall say this only once"
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Class resources list

As far as I know there is no documented way to get the list of available resources.

 

 

Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: Class resources list

Just read this interesting thread Smiley Happy .. 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..

 

Cheers.. 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: Class resources list

FYI, I replied for this - "or want the user to input the string to fetch test the existance of the resource"..
--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: Class resources list

@mantaker

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 Smiley Happy



"Listen carefully, I shall say this only once"
Highlighted
New Developer
Posts: 21
Registered: ‎10-05-2009
My Device: Curve 8310

Re: Class resources list

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.