Search in sources :

Example 16 with ExtensionResourceFilter

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);
    }
}
Also used : TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) Resource(lucee.commons.io.res.Resource) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) IOException(java.io.IOException) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) lucee.aprint(lucee.aprint)

Aggregations

ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)16 Resource (lucee.commons.io.res.Resource)13 IOException (java.io.IOException)5 MappingImpl (lucee.runtime.MappingImpl)3 ApplicationException (lucee.runtime.exp.ApplicationException)3 Query (lucee.runtime.type.Query)3 QueryImpl (lucee.runtime.type.QueryImpl)3 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 OrResourceFilter (lucee.commons.io.res.filter.OrResourceFilter)2 ResourceFilter (lucee.commons.io.res.filter.ResourceFilter)2 CompressResource (lucee.commons.io.res.type.compress.CompressResource)2 ExpressionException (lucee.runtime.exp.ExpressionException)2 PageException (lucee.runtime.exp.PageException)2 FunctionLib (lucee.transformer.library.function.FunctionLib)2 FunctionLibException (lucee.transformer.library.function.FunctionLibException)2 TagLib (lucee.transformer.library.tag.TagLib)2 TagLibException (lucee.transformer.library.tag.TagLibException)2 ServiceException (coldfusion.server.ServiceException)1