This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


java.util.jar
class JarFile

java.lang.Object extended by java.util.zip.ZipFile extended by java.util.jar.JarFile
All Implemented Interfaces:
ZipConstants

Most common way to construct:

File file = …;

JarFile jarFile = new JarFile(file);

Based on 60 examples


public class JarFile
extends ZipFile

The JarFile class is used to read the contents of a jar file from any file that can be opened with java.io.RandomAccessFile. It extends the class java.util.zip.ZipFile with support for reading an optional Manifest entry. The Manifest can be used to specify meta-information about the jar file and its entries.

Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a {@link NullPointerException} to be thrown.


Field Summary
static String MANIFEST_NAME
          The JAR manifest file name.
 
Fields inherited from class java.util.zip.ZipFile
OPEN_DELETE, OPEN_READ
 
Constructor Summary
JarFile(File file)

          Creates a new JarFile to read from the specified File object.
JarFile(File file, boolean verify)

          Creates a new JarFile to read from the specified File object.
JarFile(File file, boolean verify, int mode)

          Creates a new JarFile to read from the specified File object in the specified mode.

          Creates a new JarFile to read from the specified file name.
JarFile(String name, boolean verify)

          Creates a new JarFile to read from the specified file name.
 
Method Summary
 Enumeration

          Returns an enumeration of the zip file entries.
 ZipEntry

          Returns the ZipEntry for the given entry name or null if not found.
 InputStream

          Returns an input stream for reading the contents of the specified zip file entry.
 JarEntry

          Returns the JarEntry for the given entry name or null if not found.
 Manifest

          Returns the jar file manifest, or null if none.
 
Methods inherited from class java.util.zip.ZipFile
close, entries, finalize, getEntry, getInputStream, getName, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MANIFEST_NAME

public static final String MANIFEST_NAME
The JAR manifest file name.
Constructor Detail

JarFile

public JarFile(File file)
        throws IOException
Creates a new JarFile to read from the specified File object. The JarFile will be verified if it is signed.

Parameters:
file - the jar file to be opened for reading
Throws:
IOException - if an I/O error has occurred

JarFile

public JarFile(File file,
               boolean verify)
        throws IOException
Creates a new JarFile to read from the specified File object.

Parameters:
file - the jar file to be opened for reading
verify - whether or not to verify the jar file if it is signed.
Throws:
IOException - if an I/O error has occurred

JarFile

public JarFile(File file,
               boolean verify,
               int mode)
        throws IOException
Creates a new JarFile to read from the specified File object in the specified mode. The mode argument must be either OPEN_READ or OPEN_READ | OPEN_DELETE.

Parameters:
file - the jar file to be opened for reading
verify - whether or not to verify the jar file if it is signed.
mode - the mode in which the file is to be opened
Throws:
IOException - if an I/O error has occurred

JarFile

public JarFile(String name)
        throws IOException
Creates a new JarFile to read from the specified file name. The JarFile will be verified if it is signed.

Parameters:
name - the name of the jar file to be opened for reading
Throws:
IOException - if an I/O error has occurred

JarFile

public JarFile(String name,
               boolean verify)
        throws IOException
Creates a new JarFile to read from the specified file name.

Parameters:
name - the name of the jar file to be opened for reading
verify - whether or not to verify the jar file if it is signed.
Throws:
IOException - if an I/O error has occurred
Method Detail

entries

public Enumeration entries()
Returns an enumeration of the zip file entries.

Overrides:
entries in class ZipFile

getEntry

public ZipEntry getEntry(String name)
Returns the ZipEntry for the given entry name or null if not found.

Overrides:
getEntry in class ZipFile
Parameters:
name - the jar file entry name
Returns:
the ZipEntry for the given entry name or null if not found

getInputStream

public synchronized InputStream getInputStream(ZipEntry ze)
                                        throws IOException
Returns an input stream for reading the contents of the specified zip file entry.

Overrides:
getInputStream in class ZipFile
Parameters:
ze - the zip file entry
Returns:
an input stream for reading the contents of the specified zip file entry
Throws:
IOException - if an I/O error has occurred

getJarEntry

public JarEntry getJarEntry(String name)
Returns the JarEntry for the given entry name or null if not found.

Parameters:
name - the jar file entry name
Returns:
the JarEntry for the given entry name or null if not found.

getManifest

public Manifest getManifest()
                     throws IOException
Returns the jar file manifest, or null if none.

Returns:
the jar file manifest, or null if none
Throws:
IOException


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.