JarInflater

Tuesday, April 12th, 2005 - Español English

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.

  1. /**
  2. * 4/12/2005 19:05
  3. * Miguel de Benito Delgado <nonick AT 8027 DOT org>
  4. *
  5. * This little app demonstrates how to load an image from a zip file.
  6. *
  7. * This method was intended to be used as a means for reducing download
  8. * time of resources but, for certain applications, zipping only gave a 5%
  9. * file size decrease.
  10. *
  11. * Nevertheless, using a zip to store resources has its advantages, namely
  12. * that you get access to named files. No more need to store file pointers
  13. * sometime during the resource build process. One could simply pack everything
  14. * into a zip file and let JarInflater do the work of providing us with
  15. * InputStreams to be used by MediaManager.
  16. *
  17. * As to application's text data, the gain would double: not only would they be
  18. * compressed, but we could, using a readline()-like function, parse the strings
  19. * quite easily, again without having to care about offsets or string sizes.
  20. *
  21. * Of course, I might be wrong... ;)
  22. */
  23.  
  24. import com.nttdocomo.util.JarInflater;
  25. import com.nttdocomo.ui.*;
  26. import javax.microedition.io.Connector;
  27. import java.io.InputStream;
  28.  
  29. /**
  30. *
  31. */
  32. public class InflaterTest extends IApplication implements ComponentListener
  33. {
  34. Panel dialog;
  35. Button buttonOk;
  36. ImageLabel picture;
  37.  
  38. /**
  39. * Application's entry point.
  40. */
  41. public void start()
  42. {
  43. try {
  44. /// Open the zip archive
  45. InputStream is = Connector.openInputStream("resource:///img.zip");
  46. JarInflater reader = new JarInflater(is);
  47. is.close();
  48. /// and decompress a file in it.
  49. is = reader.getInputStream("img.gif");
  50.  
  51. /// Now use the image as usual.
  52. MediaImage img = MediaManager.getImage(is);
  53. img.use();
  54. is.close();
  55. picture = new ImageLabel(img.getImage());
  56.  
  57. /// Finally build the panel
  58. dialog = new Panel();
  59. buttonOk = new Button("Close");
  60. HTMLLayout layout = new HTMLLayout();
  61. dialog.setLayoutManager(layout);
  62.  
  63. dialog.setTitle("Zipped!");
  64.  
  65. layout.begin(HTMLLayout.CENTER);
  66.  
  67. dialog.add(picture);
  68.  
  69. layout.br();
  70.  
  71. dialog.add(buttonOk);
  72.  
  73. layout.end();
  74.  
  75. /// Set things up
  76. buttonOk.requestFocus();
  77. Display.setCurrent(dialog);
  78. dialog.setComponentListener(this);
  79. }
  80. // Not very sofisticated error handling...
  81. catch (Exception e) {
  82. System.out.println("ooops: " + e.toString());
  83. terminate();
  84. }
  85. }
  86.  
  87. /**
  88. * Just close the application if we are requested to.
  89. */
  90. public void componentAction(Component source, int type, int param)
  91. {
  92. if (source == buttonOk && type == BUTTON_PRESSED) {
  93. System.out.println("Bye!");
  94. terminate();
  95. }
  96. }
  97.  
  98. }
  99.  

One Response to “ JarInflater ”

  1. 8027.org » Blog Archive » Video on Doja example Says:

    […] peat top;} */ 8027.org YaWL… « JarInflater Video on Doja example Last week I had to test if some video in .3gp format worked on […]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>