it.eng.test
Class JarResources

java.lang.Object
  extended by it.eng.test.JarResources

public final class JarResources
extends java.lang.Object

JarResources: JarResources maps all resources included in a Zip or Jar file. Additionaly, it provides a method to extract one as a blob.


Field Summary
 boolean debugOn
           
private  java.util.Hashtable htJarContents
           
private  java.util.Hashtable htSizes
           
private  java.lang.String jarFileName
           
 
Constructor Summary
JarResources(java.lang.String jarFileName)
          creates a JarResources.
 
Method Summary
private  java.lang.String dumpZipEntry(java.util.zip.ZipEntry ze)
          Dumps a zip entry into a string.
 byte[] getResource(java.lang.String name)
          Extracts a jar resource as a blob.
private  void init()
          initializes internal hash tables with Jar file resources.
static void main(java.lang.String[] args)
          Is a test driver.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debugOn

public boolean debugOn

htSizes

private java.util.Hashtable htSizes

htJarContents

private java.util.Hashtable htJarContents

jarFileName

private java.lang.String jarFileName
Constructor Detail

JarResources

public JarResources(java.lang.String jarFileName)
creates a JarResources. It extracts all resources from a Jar into an internal hashtable, keyed by resource names.

Parameters:
jarFileName - a jar or zip file
Method Detail

getResource

public byte[] getResource(java.lang.String name)
Extracts a jar resource as a blob.

Parameters:
name - a resource name.

init

private void init()
initializes internal hash tables with Jar file resources.


dumpZipEntry

private java.lang.String dumpZipEntry(java.util.zip.ZipEntry ze)
Dumps a zip entry into a string.

Parameters:
ze - a ZipEntry

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Is a test driver. Given a jar file and a resource name, it trys to extract the resource and then tells us whether it could or not. Example Let's say you have a JAR file which jarred up a bunch of gif image files. Now, by using JarResources, you could extract, create, and display those images on-the-fly.
     ...
     JarResources JR=new JarResources("GifBundle.jar");
     Image image=Toolkit.createImage(JR.getResource("logo.gif");
     Image logo=Toolkit.getDefaultToolkit().createImage(
                   JR.getResources("logo.gif")
                   );
     ...
 

Throws:
java.io.IOException