org.sape.carbon.core.util.jar
Class EnhancedJarFile

java.lang.Object
  |
  +--org.sape.carbon.core.util.jar.EnhancedJarFile

public class EnhancedJarFile
extends Object

This class enhances functionality of java.util.jar.JarFile. Additional functionality includes jar entry removal, the ability to list the entries within a directory within the jar, and the ability to get an output stream for modifying extisting entries.

Since:
carbon 1.0
Version:
$Revision: 1.11 $ ($Author: dvoet $)
Author:
Doug Voet, April 2002
See Also:
Copyright 2002 Sapient

Field Summary
private  JarFile jar
           
static String JAR_DELIMETER
           
private  org.apache.commons.logging.Log log
          Provides a handle to Apache-commons logger
 
Constructor Summary
EnhancedJarFile(File file)
           
EnhancedJarFile(File file, boolean verify)
           
EnhancedJarFile(File file, boolean verify, int mode)
           
EnhancedJarFile(String name)
           
EnhancedJarFile(String name, boolean verify)
           
 
Method Summary
 void close()
           
 Enumeration entries()
           
 ZipEntry getEntry(String arg0)
           
 JarEntryOutputStream getEntryOutputStream(String entryName)
          Creates a new output entry stream within the jar.
 InputStream getInputStream(ZipEntry arg0)
           
 JarEntry getJarEntry(String arg0)
           
 Manifest getManifest()
           
 String getName()
           
 List listSubEntries(String entryName)
          Returns a list of entries that are immediately below the entry named by entryName in the jar's directory structure.
 void removeEntry(JarEntry entry)
          Removes the given entry from the jar.
 int size()
           
(package private)  void swapJars(File newJarFile)
          Utility method used to swap the underlying jar file out for the new one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JAR_DELIMETER

public static final String JAR_DELIMETER
See Also:
Constant Field Values

log

private org.apache.commons.logging.Log log
Provides a handle to Apache-commons logger


jar

private JarFile jar
Constructor Detail

EnhancedJarFile

public EnhancedJarFile(String name)
                throws IOException
See Also:
JarFile.JarFile(java.lang.String)

EnhancedJarFile

public EnhancedJarFile(String name,
                       boolean verify)
                throws IOException
See Also:
JarFile.JarFile(java.lang.String, boolean)

EnhancedJarFile

public EnhancedJarFile(File file)
                throws IOException
See Also:
JarFile.JarFile(java.io.File)

EnhancedJarFile

public EnhancedJarFile(File file,
                       boolean verify)
                throws IOException
See Also:
JarFile.JarFile(java.io.File, boolean)

EnhancedJarFile

public EnhancedJarFile(File file,
                       boolean verify,
                       int mode)
                throws IOException
See Also:
JarFile.JarFile(java.io.File, boolean, int)
Method Detail

listSubEntries

public List listSubEntries(String entryName)
Returns a list of entries that are immediately below the entry named by entryName in the jar's directory structure.

Parameters:
entryName - the name of the directory entry name
Returns:
List a list of java.util.jar.JarEntry objects that are immediately below the entry named by entryName in the jar's directory structure.

getEntryOutputStream

public JarEntryOutputStream getEntryOutputStream(String entryName)
Creates a new output entry stream within the jar. The entry named will be created if it does not exist within the jar already.

Parameters:
entryName - name of the entry for which to create an output stream.
Returns:
JarEntryOutputStream

removeEntry

public void removeEntry(JarEntry entry)
                 throws IOException
Removes the given entry from the jar. If the entry does not exist, the method returns without doing anything.

Parameters:
entry - entry to be removed
Throws:
IOException - if there is a problem writing the changes to the jar

entries

public Enumeration entries()
See Also:
JarFile.entries()

getEntry

public ZipEntry getEntry(String arg0)
See Also:
JarFile.getEntry(java.lang.String)

getInputStream

public InputStream getInputStream(ZipEntry arg0)
                           throws IOException
IOException
See Also:
JarFile.getInputStream(java.util.zip.ZipEntry)

getJarEntry

public JarEntry getJarEntry(String arg0)
See Also:
JarFile.getJarEntry(java.lang.String)

getManifest

public Manifest getManifest()
                     throws IOException
IOException
See Also:
JarFile.getManifest()

close

public void close()
           throws IOException
IOException
See Also:
ZipFile.close()

getName

public String getName()
See Also:
ZipFile.getName()

size

public int size()
See Also:
ZipFile.size()

swapJars

void swapJars(File newJarFile)
        throws IOException
Utility method used to swap the underlying jar file out for the new one. This method closes the old jar file, deletes it, moves the new jar file to the location where the old one used to be and opens it.

This is used when modifying the jar (removal, addition, or changes of entries)

Parameters:
newJarFile - the file object pointing to the new jar file
IOException


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.