* @param file the JAR file
* @param dir the directory to extract the component to.
*/
private void unzipComponent(String componentName, File file, File dir) {
try {
ZipFile zipFile = new JarFile(file);
// Ensure that this JAR is a component.
if (zipFile.getEntry("component.xml") == null) {
return;
}
dir.mkdir();
manager.getLog().debug("Extracting component: " + componentName);
for (Enumeration e=zipFile.entries(); e.hasMoreElements(); ) {
JarEntry entry = (JarEntry)e.nextElement();
File entryFile = new File(dir, entry.getName());
// Ignore any manifest.mf entries.
if (entry.getName().toLowerCase().endsWith("manifest.mf")) {
continue;
}
if (!entry.isDirectory()) {
entryFile.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(entryFile);
InputStream zin = zipFile.getInputStream(entry);
byte [] b = new byte[512];
int len = 0;
while ( (len=zin.read(b))!= -1 ) {
out.write(b,0,len);
}
out.flush();
out.close();
zin.close();
}
}
zipFile.close();
zipFile = null;
}
catch (Exception e) {
manager.getLog().error(e);
}