java.util.jar
public class: JarFile [javadoc |
source]
java.lang.Object
java.util.zip.ZipFile
java.util.jar.JarFile
All Implemented Interfaces:
ZipConstants
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 NullPointerException to be
thrown.
| Field Summary |
|---|
| public static final String | MANIFEST_NAME | The JAR manifest file name. |
| Constructor: |
public JarFile(String name) throws IOException {
this(new File(name), true, ZipFile.OPEN_READ);
}
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
SecurityException - if access to the file is denied
by the SecurityManager
|
public JarFile(File file) throws IOException {
this(file, true, ZipFile.OPEN_READ);
}
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
SecurityException - if access to the file is denied
by the SecurityManager
|
public JarFile(String name,
boolean verify) throws IOException {
this(new File(name), verify, ZipFile.OPEN_READ);
}
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
SecurityException - if access to the file is denied
by the SecurityManager
|
public JarFile(File file,
boolean verify) throws IOException {
this(file, verify, ZipFile.OPEN_READ);
}
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
SecurityException - if access to the file is denied
by the SecurityManager.
|
public JarFile(File file,
boolean verify,
int mode) throws IOException {
super(file, mode);
this.verify = verify;
}
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
IllegalArgumentException -
if the mode argument is invalid
SecurityException - if access to the file is denied
by the SecurityManager
- since:
1.3 -
|
| Methods from java.lang.Object: |
|---|
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from java.util.jar.JarFile Detail: |
public Enumeration entries() {
final Enumeration enum_ = super.entries();
return new Enumeration< JarEntry >() {
public boolean hasMoreElements() {
return enum_.hasMoreElements();
}
public JarFileEntry nextElement() {
ZipEntry ze = (ZipEntry)enum_.nextElement();
return new JarFileEntry(ze);
}
};
}
Returns an enumeration of the zip file entries. |
public ZipEntry getEntry(String name) {
ZipEntry ze = super.getEntry(name);
if (ze != null) {
return new JarFileEntry(ze);
}
return null;
}
Returns the ZipEntry for the given entry name or
null if not found. |
public synchronized InputStream getInputStream(ZipEntry ze) throws IOException {
maybeInstantiateVerifier();
if (jv == null) {
return super.getInputStream(ze);
}
if (!jvInitialized) {
initializeVerifier();
jvInitialized = true;
// could be set to null after a call to
// initializeVerifier if we have nothing to
// verify
if (jv == null)
return super.getInputStream(ze);
}
// wrap a verifier stream around the real stream
return new JarVerifier.VerifierStream(
getManifestFromReference(),
ze instanceof JarFileEntry ?
(JarEntry) ze : getJarEntry(ze.getName()),
super.getInputStream(ze),
jv);
}
Returns an input stream for reading the contents of the specified
zip file entry. |
public JarEntry getJarEntry(String name) {
return (JarEntry)getEntry(name);
}
Returns the JarEntry for the given entry name or
null if not found. |
public Manifest getManifest() throws IOException {
return getManifestFromReference();
}
Returns the jar file manifest, or null if none. |
boolean hasClassPathAttribute() throws IOException {
if (computedHasClassPathAttribute) {
return hasClassPathAttribute;
}
hasClassPathAttribute = false;
if (!isKnownToNotHaveClassPathAttribute()) {
JarEntry manEntry = getManEntry();
if (manEntry != null) {
byte[] b = new byte[(int)manEntry.getSize()];
DataInputStream dis = new DataInputStream(
super.getInputStream(manEntry));
dis.readFully(b, 0, b.length);
dis.close();
int last = b.length - src.length;
int i = 0;
next:
while (i< =last) {
for (int j=9; j >=0; j--) {
char c = (char) b[i+j];
c = (((c-'A")|('Z"-c)) >= 0) ? (char)(c + 32) : c;
if (c != src[j]) {
i += Math.max(j + 1 - lastOcc[c&0x7F], optoSft[j]);
continue next;
}
}
hasClassPathAttribute = true;
break;
}
}
}
computedHasClassPathAttribute = true;
return hasClassPathAttribute;
}
|