bookExamples.ch15Streams
Class Unzipper

java.lang.Object
  extended by bookExamples.ch15Streams.Unzipper

public final class Unzipper
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
           
 
Constructor Summary
Unzipper(java.io.File jarFileName)
          creates a JarResources.
Unzipper(java.lang.String jarFileName)
          creates a JarResources.
 
Method Summary
static boolean containsResource(java.io.File f, java.lang.String nativeLib)
           
 byte[] getBlob(java.lang.String name)
          Extracts a jar resource as a blob.
 java.lang.String[] getNames()
           
static void getResourceByName()
           
static void main(java.lang.String[] args)
          Is a test driver.
static void uncompressJarFile(java.io.File inputJarFile)
          Uncompress a jar file into the parent directory, creating directories on an as-needed basis.
 void verify()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debugOn

public boolean debugOn
Constructor Detail

Unzipper

public Unzipper(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

Unzipper

public Unzipper(java.io.File 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

getNames

public java.lang.String[] getNames()

getBlob

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

Parameters:
name - a resource name.

verify

public void verify()
            throws java.io.IOException
Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
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")
                   );
     ...
 


containsResource

public static boolean containsResource(java.io.File f,
                                       java.lang.String nativeLib)

getResourceByName

public static void getResourceByName()

uncompressJarFile

public static void uncompressJarFile(java.io.File inputJarFile)
Uncompress a jar file into the parent directory, creating directories on an as-needed basis.

Parameters:
inputJarFile -