java.util.jar

Class 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 StringMANIFEST_NAME
The name of the manifest entry: META-INF/MANIFEST.MF
Constructor Summary
JarFile(String fileName)
Creates a new JarFile.
JarFile(String fileName, boolean verify)
Creates a new JarFile.
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.
Method Summary
Enumeration<JarEntry>entries()
Returns a enumeration of all the entries in the JarFile.
ZipEntrygetEntry(String name)
XXX It actually returns a JarEntry not a zipEntry
InputStreamgetInputStream(ZipEntry entry)
Returns an input stream for the given entry.
JarEntrygetJarEntry(String name)
Returns the JarEntry that belongs to the name if such an entry exists in the JarFile.
ManifestgetManifest()
Returns the manifest for this JarFile or null when the JarFile does not contain a manifest file.

Field Detail

MANIFEST_NAME

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

Constructor Detail

JarFile

public JarFile(String fileName)
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)
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)
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)
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)
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()
Returns a enumeration of all the entries in the JarFile. Note that also the Jar META-INF entries are returned.

Throws: IllegalStateException when the JarFile is already closed

getEntry

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

Parameters: name XXX

getInputStream

public InputStream getInputStream(ZipEntry entry)
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.

Parameters: entry The entry to get the input stream for.

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()
Returns the manifest for this JarFile or null when the JarFile does not contain a manifest file.