| 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 -
|
| Method from java.util.jar.JarFile Detail: |
public Enumeration<JarEntry> 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. |
Enumeration<JarEntry> entries2() {
ensureInitialization();
if (jv != null) {
return jv.entries2(this, super.entries());
}
// screen out entries which are never signed
final Enumeration enum_ = super.entries();
return new Enumeration< JarEntry >() {
ZipEntry entry;
public boolean hasMoreElements() {
if (entry != null) {
return true;
}
while (enum_.hasMoreElements()) {
ZipEntry ze = (ZipEntry) enum_.nextElement();
if (JarVerifier.isSigningRelated(ze.getName())) {
continue;
}
entry = ze;
return true;
}
return false;
}
public JarFileEntry nextElement() {
if (hasMoreElements()) {
ZipEntry ze = entry;
entry = null;
return new JarFileEntry(ze);
}
throw new NoSuchElementException();
}
};
}
Returns an enumeration of the zip file entries
excluding internal JAR mechanism entries and including
signed entries missing from the ZIP directory. |
Enumeration<String> entryNames(CodeSource[] cs) {
ensureInitialization();
if (jv != null) {
return jv.entryNames(this, cs);
}
/*
* JAR file has no signed content. Is there a non-signing
* code source?
*/
boolean includeUnsigned = false;
for (int i = 0; i < cs.length; i++) {
if (cs[i].getCodeSigners() == null) {
includeUnsigned = true;
break;
}
}
if (includeUnsigned) {
return unsignedEntryNames();
} else {
return new Enumeration< String >() {
public boolean hasMoreElements() {
return false;
}
public String nextElement() {
throw new NoSuchElementException();
}
};
}
}
|
CodeSource getCodeSource(URL url,
String name) {
ensureInitialization();
if (jv != null) {
if (jv.eagerValidation) {
CodeSource cs = null;
JarEntry je = getJarEntry(name);
if (je != null) {
cs = jv.getCodeSource(url, this, je);
} else {
cs = jv.getCodeSource(url, name);
}
return cs;
} else {
return jv.getCodeSource(url, name);
}
}
return JarVerifier.getUnsignedCS(url);
}
|
CodeSource[] getCodeSources(URL url) {
ensureInitialization();
if (jv != null) {
return jv.getCodeSources(this, url);
}
/*
* JAR file has no signed content. Is there a non-signing
* code source?
*/
Enumeration unsigned = unsignedEntryNames();
if (unsigned.hasMoreElements()) {
return new CodeSource[]{JarVerifier.getUnsignedCS(url)};
} else {
return null;
}
}
|
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. |
List getManifestDigests() {
ensureInitialization();
if (jv != null) {
return jv.getManifestDigests();
}
return new ArrayList();
}
|
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()];
try (DataInputStream dis = new DataInputStream(
super.getInputStream(manEntry))) {
dis.readFully(b, 0, b.length);
}
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;
}
|
JarEntry newEntry(ZipEntry ze) {
return new JarFileEntry(ze);
}
|
void setEagerValidation(boolean eager) {
try {
maybeInstantiateVerifier();
} catch (IOException e) {
throw new RuntimeException(e);
}
if (jv != null) {
jv.setEagerValidation(eager);
}
}
|