throws IOException {
LOGGER.warning("Exploding '" + warfile + "' into " + exploded);
if (exploded.exists()) {
FileUtil.deleteContentsOf(exploded);
}
JarFileCollection war = new JarFileCollection(warfile);
List<String> entries = new ArrayList<String>(war.getFileNames());
Collections.sort(entries, new WarComparator());
for (String entry : entries) {
// change (back)slashes to whatever our local OS uses
String entryname = entry.replace('/', File.separatorChar);
entryname = entryname.replace('\\', File.separatorChar);
File destfile = new File(exploded, entryname);
File tmpDestFile = new File(exploded, entryname + ".tmp");
File dir = destfile.getParentFile();
if (!dir.exists()) {
dir.mkdirs();
}
LOGGER.info("extracting " + entry + " to " + tmpDestFile);
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(tmpDestFile);
war.writeEntryTo(entry, fileOutputStream);
fileOutputStream.close();
fileOutputStream = null;
if (!tmpDestFile.renameTo(destfile)) {
throw new IOException(
"Cannot rename " + tmpDestFile + " to " + destfile);
}
if (!destfile.exists()) {
throw new IOException(destfile + " does not exist!");
}
} catch (IOException ioe) {
LOGGER.log(Level.WARNING, "", ioe);
tmpDestFile.delete();
} finally {
if (fileOutputStream != null) {
fileOutputStream.close();
}
}
}
war.releaseResources();
}