@SuppressWarnings("rawtypes") final class ZipResources { private Hashtable htSizes=new Hashtable(); private Hashtable htJarContents=new Hashtable(); private String jarFileName; public LevelResources(String jarFileName) { this.jarFileName=jarFileName; init(); } public byte[] getResource(String name) { return (byte[])htJarContents.get(name); } @SuppressWarnings({ "unchecked" }) private void init() { try { ZipFile zf = new ZipFile(jarFileName); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze = (ZipEntry)e.nextElement(); htSizes.put(ze.getName(), (int) ze.getSize()); } zf.close(); FileInputStream fis = new FileInputStream(jarFileName); BufferedInputStream bis = new BufferedInputStream(fis); ZipInputStream zis = new ZipInputStream(bis); ZipEntry ze = null; while ((ze = zis.getNextEntry()) != null) { if (ze.isDirectory()) { continue; } int size = (int)ze.getSize(); if (size == -1) { size = ((Integer)htSizes.get(ze.getName())).intValue(); } byte[] b = new byte[size]; int rb = 0; int chunk = 0; while ((size - rb) > 0) { chunk=zis.read(b, rb, size - rb); if (chunk==-1) { break; } rb += chunk; } htJarContents.put(ze.getName(),b); } } catch (NullPointerException e) { System.out.println("done."); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }