Resource packing

Instead of using the “getResourceAsStream” function directly to load your data files, you can make your own loading system where all your files are stored in a big “resource-pack” file in the jar. This will make the jar file compress more efficiently.

The concept is pretty simple. You have to write a utility that joins together your datafiles into one big file, and that also produces some kind of index data to keep track of the offset positions of the different files within the big datafile. Then you have to write your own loader routine that seeks to the right offset in the big datapack and loads your data neatly into a bytearray. Images in J2ME can be created directly from bytearray data, so you won’t have any problems packing together your PNG-files as well.

Does it sound hard and confusing? Well, it doesn’t have to be. I’ve already created a tool to help you. It’s called BamFS, it merges your data files together in a datapack and also creates a static class for you to use directly in your project. The static class includes pointer constants to identify your files, functions to load the data, and also a createImage function for you to use. Check it out, it’s free as well! :)