test/tools/jar/index/MetaInf.java
Print this page
@@ -60,12 +60,18 @@
}
}
static boolean contains(File jarFile, String entryName)
throws IOException {
- return new ZipFile(jarFile).getEntry(entryName) != null;
+ ZipFile zf = new ZipFile(jarFile);
+ if ( zf != null ) {
+ boolean result = zf.getEntry(entryName) != null;
+ zf.close();
+ return result;
}
+ return false;
+ }
static void checkContains(File jarFile, String entryName)
throws IOException {
if (! contains(jarFile, entryName))
throw new Error(String.format("expected jar %s to contain %s",
@@ -92,13 +98,17 @@
new InputStreamReader(
f.getInputStream(f.getJarEntry(INDEX))));
String line;
while ((line = index.readLine()) != null) {
if (line.equals(SERVICES)) {
+ index.close();
+ f.close();
return;
}
}
+ index.close();
+ f.close();
throw new Error(SERVICES + " not indexed.");
}
public static void main(String[] args) throws IOException {
testIndex("a.jar"); // a path with parent == null