java.util.jar
Class JarFile

java.lang.Object
  extended by java.util.zip.ZipFile
      extended by java.util.jar.JarFile

public class JarFile
extends ZipFile

Representation of a jar file.

Note that this class is not a subclass of java.io.File but a subclass of java.util.zip.ZipFile and you can only read JarFiles with it (although there are constructors that take a File object).

Since:
1.2

Field Summary
static int CENATT
           
static int CENATX
           
static int CENCOM
           
static int CENCRC
           
static int CENDSK
           
static int CENEXT
           
static int CENFLG
           
static int CENHDR
           
static int CENHOW
           
static int CENLEN
           
static int CENNAM
           
static int CENOFF
           
static long CENSIG
           
static int CENSIZ
           
static int CENTIM
           
static int CENVEM
           
static int CENVER
           
static int ENDCOM
           
static int ENDHDR
           
static int ENDOFF
           
static long ENDSIG
           
static int ENDSIZ
           
static int ENDSUB
           
static int ENDTOT
           
static int EXTCRC
           
static int EXTHDR
           
static int EXTLEN
           
static long EXTSIG
           
static int EXTSIZ
           
static int LOCCRC
           
static int LOCEXT
           
static int LOCFLG
           
static int LOCHDR
           
static int LOCHOW
           
static int LOCLEN
           
static int LOCNAM
           
static long LOCSIG
           
static int LOCSIZ
           
static int LOCTIM
           
static int LOCVER
           
static String MANIFEST_NAME
          The name of the manifest entry: META-INF/MANIFEST.MF
 
Fields inherited from class java.util.zip.ZipFile
OPEN_DELETE, OPEN_READ
 
Constructor Summary
JarFile(File file)
          Creates a new JarFile.
JarFile(File file, boolean verify)
          Creates a new JarFile.
JarFile(File file, boolean verify, int mode)
          Creates a new JarFile with the indicated mode.
JarFile(String fileName)
          Creates a new JarFile.
JarFile(String fileName, boolean verify)
          Creates a new JarFile.
 
Method Summary
 Enumeration<JarEntry> entries()
          Returns a enumeration of all the entries in the JarFile.
 ZipEntry getEntry(String name)
          XXX It actually returns a JarEntry not a zipEntry
 InputStream getInputStream(ZipEntry entry)
          Returns an input stream for the given entry.
 JarEntry getJarEntry(String name)
          Returns the JarEntry that belongs to the name if such an entry exists in the JarFile.
 Manifest getManifest()
          Returns the manifest for this JarFile or null when the JarFile does not contain a manifest file.
 
Methods inherited from class java.util.zip.ZipFile
close, finalize, getName, size
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MANIFEST_NAME

public static final String MANIFEST_NAME
The name of the manifest entry: META-INF/MANIFEST.MF

See Also:
Constant Field Values

LOCHDR

public static final int LOCHDR
See Also:
Constant Field Values

LOCSIG

public static final long LOCSIG
See Also:
Constant Field Values

LOCVER

public static final int LOCVER
See Also:
Constant Field Values

LOCFLG

public static final int LOCFLG
See Also:
Constant Field Values

LOCHOW

public static final int LOCHOW
See Also:
Constant Field Values

LOCTIM

public static final int LOCTIM
See Also:
Constant Field Values

LOCCRC

public static final int LOCCRC
See Also:
Constant Field Values

LOCSIZ

public static final int LOCSIZ
See Also:
Constant Field Values

LOCLEN

public static final int LOCLEN
See Also:
Constant Field Values

LOCNAM

public static final int LOCNAM
See Also:
Constant Field Values

LOCEXT

public static final int LOCEXT
See Also:
Constant Field Values

EXTSIG

public static final long EXTSIG
See Also:
Constant Field Values

EXTHDR

public static final int EXTHDR
See Also:
Constant Field Values

EXTCRC

public static final int EXTCRC
See Also:
Constant Field Values

EXTSIZ

public static final int EXTSIZ
See Also:
Constant Field Values

EXTLEN

public static final int EXTLEN
See Also:
Constant Field Values

CENSIG

public static final long CENSIG
See Also:
Constant Field Values

CENHDR

public static final int CENHDR
See Also:
Constant Field Values

CENVEM

public static final int CENVEM
See Also:
Constant Field Values

CENVER

public static final int CENVER
See Also:
Constant Field Values

CENFLG

public static final int CENFLG
See Also:
Constant Field Values

CENHOW

public static final int CENHOW
See Also:
Constant Field Values

CENTIM

public static final int CENTIM
See Also:
Constant Field Values

CENCRC

public static final int CENCRC
See Also:
Constant Field Values

CENSIZ

public static final int CENSIZ
See Also:
Constant Field Values

CENLEN

public static final int CENLEN
See Also:
Constant Field Values

CENNAM

public static final int CENNAM
See Also:
Constant Field Values

CENEXT

public static final int CENEXT
See Also:
Constant Field Values

CENCOM

public static final int CENCOM
See Also:
Constant Field Values

CENDSK

public static final int CENDSK
See Also:
Constant Field Values

CENATT

public static final int CENATT
See Also:
Constant Field Values

CENATX

public static final int CENATX
See Also:
Constant Field Values

CENOFF

public static final int CENOFF
See Also:
Constant Field Values

ENDSIG

public static final long ENDSIG
See Also:
Constant Field Values

ENDHDR

public static final int ENDHDR
See Also:
Constant Field Values

ENDSUB

public static final int ENDSUB
See Also:
Constant Field Values

ENDTOT

public static final int ENDTOT
See Also:
Constant Field Values

ENDSIZ

public static final int ENDSIZ
See Also:
Constant Field Values

ENDOFF

public static final int ENDOFF
See Also:
Constant Field Values

ENDCOM

public static final int ENDCOM
See Also:
Constant Field Values
Constructor Detail

JarFile

public JarFile(String fileName)
        throws FileNotFoundException,
               IOException
Creates a new JarFile. All jar entries are verified (when a Manifest file for this JarFile exists). You need to actually open and read the complete jar entry (with getInputStream()) to check its signature.

Parameters:
fileName - the name of the file to open
Throws:
FileNotFoundException - if the fileName cannot be found
IOException - if another IO exception occurs while reading

JarFile

public JarFile(String fileName,
               boolean verify)
        throws FileNotFoundException,
               IOException
Creates a new JarFile. If verify is true then all jar entries are verified (when a Manifest file for this JarFile exists). You need to actually open and read the complete jar entry (with getInputStream()) to check its signature.

Parameters:
fileName - the name of the file to open
verify - checks manifest and entries when true and a manifest exists, when false no checks are made
Throws:
FileNotFoundException - if the fileName cannot be found
IOException - if another IO exception occurs while reading

JarFile

public JarFile(File file)
        throws FileNotFoundException,
               IOException
Creates a new JarFile. All jar entries are verified (when a Manifest file for this JarFile exists). You need to actually open and read the complete jar entry (with getInputStream()) to check its signature.

Parameters:
file - the file to open as a jar file
Throws:
FileNotFoundException - if the file does not exits
IOException - if another IO exception occurs while reading

JarFile

public JarFile(File file,
               boolean verify)
        throws FileNotFoundException,
               IOException
Creates a new JarFile. If verify is true then all jar entries are verified (when a Manifest file for this JarFile exists). You need to actually open and read the complete jar entry (with getInputStream()) to check its signature.

Parameters:
file - the file to open to open as a jar file
verify - checks manifest and entries when true and a manifest exists, when false no checks are made
Throws:
FileNotFoundException - if file does not exist
IOException - if another IO exception occurs while reading

JarFile

public JarFile(File file,
               boolean verify,
               int mode)
        throws FileNotFoundException,
               IOException,
               IllegalArgumentException
Creates a new JarFile with the indicated mode. If verify is true then all jar entries are verified (when a Manifest file for this JarFile exists). You need to actually open and read the complete jar entry (with getInputStream()) to check its signature. manifest and if the manifest exists and verify is true verfies it.

Parameters:
file - the file to open to open as a jar file
verify - checks manifest and entries when true and a manifest exists, when false no checks are made
mode - either ZipFile.OPEN_READ or (ZipFile.OPEN_READ | ZipFile.OPEN_DELETE)
Throws:
FileNotFoundException - if the file does not exist
IOException - if another IO exception occurs while reading
IllegalArgumentException - when given an illegal mode
Since:
1.3
Method Detail

entries

public Enumeration<JarEntry> entries()
                              throws IllegalStateException
Returns a enumeration of all the entries in the JarFile. Note that also the Jar META-INF entries are returned.

Overrides:
entries in class ZipFile
Throws:
IllegalStateException - when the JarFile is already closed

getEntry

public ZipEntry getEntry(String name)
XXX It actually returns a JarEntry not a zipEntry

Overrides:
getEntry in class ZipFile
Parameters:
name - XXX
Returns:
the zip entry, or null if no entry with that name exists.

getInputStream

public InputStream getInputStream(ZipEntry entry)
                           throws ZipException,
                                  IOException
Returns an input stream for the given entry. If configured to verify entries, the input stream returned will verify them while the stream is read, but only on the first time.

Overrides:
getInputStream in class ZipFile
Parameters:
entry - The entry to get the input stream for.
Returns:
the input stream, or null if the requested entry does not exist.
Throws:
ZipException - XXX
IOException - XXX

getJarEntry

public JarEntry getJarEntry(String name)
Returns the JarEntry that belongs to the name if such an entry exists in the JarFile. Returns null otherwise Convenience method that just casts the result from getEntry to a JarEntry.

Parameters:
name - the jar entry name to look up
Returns:
the JarEntry if it exists, null otherwise

getManifest

public Manifest getManifest()
                     throws IOException
Returns the manifest for this JarFile or null when the JarFile does not contain a manifest file.

Throws:
IOException