java.util.jar

Class JarFile

Implemented Interfaces:
java.util.zip.ZipConstants

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 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

Fields inherited from interface java.util.zip.ZipConstants

CENATT, CENATX, CENCOM, CENCRC, CENDSK, CENEXT, CENFLG, CENHDR, CENHOW, CENLEN, CENNAM, CENOFF, CENSIG, CENSIZ, CENTIM, CENVEM, CENVER, ENDCOM, ENDHDR, ENDOFF, ENDSIG, ENDSIZ, ENDSUB, ENDTOT, EXTCRC, EXTHDR, EXTLEN, EXTSIG, EXTSIZ, LOCCRC, LOCEXT, LOCFLG, LOCHDR, LOCHOW, LOCLEN, LOCNAM, LOCSIG, LOCSIZ, LOCTIM, LOCVER

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
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, extends ZipEntry> entries, finalize, getEntry, getInputStream, getName, size

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

MANIFEST_NAME

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

Constructor Details

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

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

Method Details

entries

public Enumeration entries()
            throws IllegalStateException
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
Overrides:
getEntry in interface ZipFile
Parameters:
name - XXX

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

JarFile.java - Representation of a jar file Copyright (C) 2000, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.