int fileCnt = getFileCount();
SubMonitor progress = SubMonitor.convert(monitor, (fileCnt > 0) ? fileCnt : 500);
String archivePath = getArchivePath();
BufferedInputStream bin = new BufferedInputStream(in);
try {
TarInputStream zin = new TarInputStream(bin);
TarEntry entry = zin.getNextEntry();
while (entry != null) {
String name = entry.getName();
progress.subTask(NLS.bind(Messages.InstallableRuntime2_TaskUncompressing, name));
if (archivePath != null && name.startsWith(archivePath)) {
name = name.substring(archivePath.length());
if (name.length() > 1)
name = name.substring(1);
}
if (name != null && name.length() > 0) {
if (entry.getFileType() == TarEntry.DIRECTORY)
path.append(name).toFile().mkdirs();
else {
File dir = path.append(name).removeLastSegments(1).toFile();
if (!dir.exists())
dir.mkdirs();
FileOutputStream fout = new FileOutputStream(path.append(name).toFile());
copyWithSize(zin, fout, progress.newChild(1), (int)entry.getSize());
fout.close();
if (fileCnt <= 0)
progress.setWorkRemaining(500);
}
}
entry = zin.getNextEntry();
}
zin.close();
} catch (TarException ex) {
throw new IOException(ex);
}
}