use of lucee.commons.io.res.filter.ExtensionResourceFilter in project Lucee by lucee.
the class CompressUtil method extractTar.
private static void extractTar(Resource tarFile, Resource targetDir) throws IOException {
if (!targetDir.exists() || !targetDir.isDirectory())
throw new IOException(targetDir + " is not a existing directory");
if (!tarFile.exists())
throw new IOException(tarFile + " is not a existing file");
if (tarFile.isDirectory()) {
Resource[] files = tarFile.listResources(new ExtensionResourceFilter("tar"));
if (files == null)
throw new IOException("directory " + tarFile + " is empty");
extract(FORMAT_TAR, files, targetDir);
return;
}
// read the zip file and build a query from its contents
TarArchiveInputStream tis = null;
try {
tis = new TarArchiveInputStream(IOUtil.toBufferedInputStream(tarFile.getInputStream()));
TarArchiveEntry entry;
int mode;
while ((entry = tis.getNextTarEntry()) != null) {
// print.ln(entry);
Resource target = targetDir.getRealResource(entry.getName());
if (entry.isDirectory()) {
target.mkdirs();
} else {
Resource parent = target.getParentResource();
if (!parent.exists())
parent.mkdirs();
IOUtil.copy(tis, target, false);
}
target.setLastModified(entry.getModTime().getTime());
mode = entry.getMode();
if (mode > 0)
target.setMode(mode);
// tis.closeEntry() ;
}
} finally {
IOUtil.closeEL(tis);
}
}
Aggregations