JarInflater
Today I’ve been toying around with some ideas to reduce download times of resources in Doja applications. We have this big game here which has to download somewhere around 200KB and it just takes too much time.
After a little reading it appeared as obvious to use JarInflater, which is handily available on Doja 2.5 Overseas Edition, the platform we develop for here, and which basically reads JAR (aka ZIP) files from an InputStream and returns another InputStream for each filename we request.
Alas, for our application zipping only gave a 5% file size decrease, so we won’t be implementing it now. But, nevertheless, using a zip file to store resources has its advantages, namely that you get access to named files. No more need to store file pointers sometime during the resource build process. One could simply pack everything into a zip file and let JarInflater do the work of providing us with InputStreams to be used by MediaManager or whichever class we want.
With application’s text data, the gain would double: not only would it be compressed, but we could, using a readline()-like function, parse the strings quite easily, again without having to care about offsets nor string sizes.
I’ve written a little IApplication to demonstrate the use of JarInflater, which is quite straightforward.
/*** 4/12/2005 19:05* Miguel de Benito Delgado <nonick AT 8027 DOT org>** This little app demonstrates how to load an image from a zip file.** This method was intended to be used as a means for reducing download* time of resources but, for certain applications, zipping only gave a 5%* file size decrease.** Nevertheless, using a zip to store resources has its advantages, namely* that you get access to named files. No more need to store file pointers* sometime during the resource build process. One could simply pack everything* into a zip file and let JarInflater do the work of providing us with* InputStreams to be used by MediaManager.** As to application's text data, the gain would double: not only would they be* compressed, but we could, using a readline()-like function, parse the strings* quite easily, again without having to care about offsets or string sizes.** Of course, I might be wrong...
*/import com.nttdocomo.util.JarInflater;import com.nttdocomo.ui.*;import javax.microedition.io.Connector;import java.io.InputStream;/****/public class InflaterTest extends IApplication implements ComponentListener{Panel dialog;Button buttonOk;ImageLabel picture;/*** Application's entry point.*/public void start(){try {/// Open the zip archiveInputStream is = Connector.openInputStream("resource:///img.zip");JarInflater reader = new JarInflater(is);is.close();/// and decompress a file in it.is = reader.getInputStream("img.gif");/// Now use the image as usual.MediaImage img = MediaManager.getImage(is);img.use();is.close();picture = new ImageLabel(img.getImage());/// Finally build the paneldialog = new Panel();buttonOk = new Button("Close");HTMLLayout layout = new HTMLLayout();dialog.setLayoutManager(layout);dialog.setTitle("Zipped!");layout.begin(HTMLLayout.CENTER);dialog.add(picture);layout.br();dialog.add(buttonOk);layout.end();/// Set things upbuttonOk.requestFocus();Display.setCurrent(dialog);dialog.setComponentListener(this);}// Not very sofisticated error handling...catch (Exception e) {System.out.println("ooops: " + e.toString());terminate();}}/*** Just close the application if we are requested to.*/public void componentAction(Component source, int type, int param){if (source == buttonOk && type == BUTTON_PRESSED) {System.out.println("Bye!");terminate();}}}- Download this code: InflaterTest.java


April 25th, 200510:23 am at
[…] peat top;} */ 8027.org YaWL… « JarInflater Video on Doja example Last week I had to test if some video in .3gp format worked on […]