And if you’re stuck with jre < 1.6 compatibility, you could always just zip your images and rename the zip to .class. f you download it over an urlconnection with the property useCache(true) it will cache your zip…
Below is an excerpt I copy pasted from my IO lib (some helper methods might be missing, but you get the point), the download method would return a byte[] of the zipped data in your case, which you can then feed to the decompress method:
public synchronized static byte[] downloadData(String resource, Class loader, ResourceInfo info, ProgressListener plistener, boolean cache)
{
try
{
InputStream is = openStream(resource, loader, info, cache);
DataInputStream dis = new DataInputStream(is);
if (dis==null) {
Log.log(this, "Resource not found: " + resource);
return null;
}
int length=dis.available();
//read min blocks of 8kb to force frequent updates for plistener (=~1update/sec on a 56k modem)
if (length <= 0) length = 8192;
//read max blocks of 100kb to prevent downloading all data in one sweep
if (length >= 10240) length = 10240;
byte[] chunk=new byte[length];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
//set the progresslistener if available
//if (plistener != null) plistener.next(plistener.DOWNLOAD);
//read in bytes from the stream & update the progresslistener if available
int bytesRead = 0;
while((bytesRead = dis.read(chunk,0,length)) != -1) {
//System.out.println("bytes read from bis: "+bytesRead);
bos.write(chunk,0,bytesRead);
//if(plistener!=null) plistener.update(bytesRead);
}
bos.flush();
closeStream(dis);
closeStream(is);
return bos.toByteArray();
}
catch(Exception e) {
Log.log(this, e);
return null;
}
}
public synchronized static void decompress(byte[] data, ProgressListener plistener)
{
//check how many zipentries the data contains
int size=getNrEntries(data),index=0;
sizes = new String[size*2];
//check if there are any entries to process and tell the progress listener
if(size>0) {
Log.log(this, "Decompressing: "+size+" zipentries found");
//if(plistener!=null) plistener.init(size);
}
else
{
Log.log(this, "Decompressing: no zip entries in data");
return;
}
try
{
ZipEntry ze;
ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(data));
while ((ze=zis.getNextEntry())!=null)
{
if (ze.isDirectory()) {
continue;
}
size=(int)ze.getSize();
sizes[index++]=ze.getName();
sizes[index++]=""+size;
Log.log(this, "Decompressing: zip entry: "+ze.getName()+","+"size="+size);
//if this is a valid entry, decompress it
if (size>-1)
{
//set the progresslistener for this entry
//if(plistener!=null) plistener.next(plistener.DECOMP);
byte[] decompData = new byte[(int)size];
int bytesRead=0;
int chunk=0;
while ((size - bytesRead) > 0)
{
chunk=zis.read(decompData,bytesRead,(int)size - bytesRead);
if (chunk==-1) {
break;
}
bytesRead+=chunk;
//if(plistener!=null) plistener.update(chunk);
}
//cache the entry in the game cache
GameContext.addObject(ze.getName(),decompData);
Log.log(this, "Decompressing: zip entry: "+ze.getName()+" bytes read="+bytesRead+",size="+size+",compressed size="+ze.getCompressedSize());
}
else
{
Log.log(this, "Decompressing: zip entry: "+ze.getName()+" has unknown size");
continue;
}
}
}
catch (NullPointerException e) {
Log.log(this, e);
}
catch (FileNotFoundException e) {
Log.log(this, e);
}
catch (IOException e) {
Log.log(this, e);
}
}