// Delete any remnants of this expanded profile
if (destination.exists()) {
FileUtils.deleteDirectory(destination);
}
BasicZipFile zip = new BasicZipFile(source);
try {
// count the zip entries so we can do progress bar
long totalSize = 0L;
for (Enumeration<? extends ZipEntry> it = zip.entries(); it
.hasMoreElements();) {
ZipEntry e = it.nextElement();
totalSize += e.getSize();
}
long bytesSoFar = 0L;
for (Enumeration<? extends ZipEntry> it = zip.entries(); it
.hasMoreElements();) {
ZipEntry entry = it.nextElement();
// zip entries can be created on windows or unix, and can retain
// the path separator for that platform. We must ensure that
// the paths we find inside the zip file will work on the platform
// we are running on. Technically, zip entry paths should be
// created using the unix separator, no matter what platform they
// are created on - but this is not always done correctly.
final String entryName = getPlatformSpecificPath(entry.getName());
File expandedFile = new File(destination + File.separator
+ entryName);
BufferedInputStream in = new BufferedInputStream(zip
.getInputStream(entry));
FileUtils.forceMkdir(expandedFile.getParentFile());
BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream(expandedFile));
bytesSoFar = readFile(in, out, observer, bytesSoFar, totalSize);
}
observer.onProgress(UNITY_PERCENT);
} finally {
zip.close();
}
}