- Catch unzip fd leaks on error
      - Move 2 test classes out of the lib
This commit is contained in:
zzz
2009-07-31 17:55:38 +00:00
parent 0bef85277e
commit 1cba7b8ec1
3 changed files with 7 additions and 3 deletions

View File

@ -76,9 +76,10 @@ public class FileUtil {
} }
public static boolean extractZip(File zipfile, File targetDir) { public static boolean extractZip(File zipfile, File targetDir) {
ZipFile zip = null;
try { try {
byte buf[] = new byte[16*1024]; byte buf[] = new byte[16*1024];
ZipFile zip = new ZipFile(zipfile); zip = new ZipFile(zipfile);
Enumeration entries = zip.entries(); Enumeration entries = zip.entries();
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry)entries.nextElement(); ZipEntry entry = (ZipEntry)entries.nextElement();
@ -124,13 +125,16 @@ public class FileUtil {
} }
} }
} }
zip.close();
return true; return true;
} catch (IOException ioe) { } catch (IOException ioe) {
System.err.println("ERROR: Unable to extract the zip file"); System.err.println("ERROR: Unable to extract the zip file");
ioe.printStackTrace(); ioe.printStackTrace();
return false; return false;
} } finally {
if (zip != null) {
try { zip.close(); } catch (IOException ioe) {}
}
}
} }
/** /**