Rambling about image loading...
In my quest to find a reasonably reliable way to load image files into an applet I have come up with yet another tremendously annoying problem and am once again seeking for better options. I'm wondering if anyone else in here would have any fresh ideas for this.
Firstly, some background: I'm working on a multiplayer game client applet. The applet loads image data from a) the jar file containing the applet itself, b) from user-specific jar files generated by the server application and c) occsaionally from separate files located in the server.
The main issue with this equation are the resource jar files. They are essential because they contain hundreds of small images that are necessary for running the application as it is and loading those images one at a time is really slow. The problem is that if for some reason any of these jar files don't contain some file they are supposed to Java registers the zip file as closed and refuses to do further reads into this file.
Now, the methods I've gone with so far are:
- Toolkit.getImage(): Most reliable so far but lacks the possibility to track progress or really catch errors. If the archive file is broken the errors are printed into the java console but the application does not register that and keeps running happily without graphics.
- Toolkit.getImage() with MediaTracker: Adds progress tracking to above. However, a broken jar file causes mt's wait method to lock completely and at least with Mozilla Firefox also locks the whole browser up(I can only close it through task manager in Windows). Needless to say, not what I'd call optimal solution...
- ImageIO: Not supported by Opera Java VM (not sure if it's in general or version specific). Also, on some java versions does not work with PNG files that have small palettes (the graphics resources in our application are shared with mobile clients which means there are plenty of these).
So, that's what I've learned so far after plenty of trial, error and frustration. I'm aware of the fact that the most obvious solution would be to make sure there are no broken resource files, but as I tend to always assume things are going to break down sooner or later (especially if made by me :o ) I'd prefer having something that will at least break with some grace.