Search in sources :

Example 1 with XZCompressorInputStream

use of org.apache.commons.compress.compressors.xz.XZCompressorInputStream in project knime-core by knime.

the class ExtractTarGz method execute.

@Override
public IStatus execute(final Map<String, Object> parameters) {
    try {
        String source = readParameter(parameters, SOURCE_ARCHIVE);
        String targetDir = readParameter(parameters, TARGET_DIR);
        File destDir;
        Path targetDirPath = Paths.get(targetDir);
        if (targetDirPath.isAbsolute()) {
            // targetDir is absolute path or contains @artifact
            destDir = targetDirPath.toFile();
        } else {
            // targetDir is something like '.'
            IProfile profile = (IProfile) parameters.get("profile");
            File installFolder = new File(profile.getProperty(IProfile.PROP_INSTALL_FOLDER));
            destDir = new File(installFolder, targetDir);
        }
        try (InputStream fileInputStream = FileUtil.openInputStream(source)) {
            InputStream in;
            if (StringUtils.endsWithIgnoreCase(source, ".tar.gz") || StringUtils.endsWithIgnoreCase(source, ".tgz")) {
                in = new GzipCompressorInputStream(fileInputStream);
            } else if (StringUtils.endsWithIgnoreCase(source, ".tar.bz2")) {
                in = new BZip2CompressorInputStream(fileInputStream);
            } else if (StringUtils.endsWithIgnoreCase(source, ".tar.xz")) {
                in = new XZCompressorInputStream(fileInputStream);
            } else {
                in = fileInputStream;
            }
            untar(in, destDir);
        }
        return Status.OK_STATUS;
    } catch (Throwable e) {
        return new Status(IStatus.ERROR, bundle.getSymbolicName(), e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) XZCompressorInputStream(org.apache.commons.compress.compressors.xz.XZCompressorInputStream) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) InputStream(java.io.InputStream) IProfile(org.eclipse.equinox.p2.engine.IProfile) File(java.io.File) XZCompressorInputStream(org.apache.commons.compress.compressors.xz.XZCompressorInputStream)

Example 2 with XZCompressorInputStream

use of org.apache.commons.compress.compressors.xz.XZCompressorInputStream in project uPortal by Jasig.

the class JaxbPortalDataHandlerService method importDataArchive.

private void importDataArchive(Resource archive, InputStream resourceStream, BatchImportOptions options) {
    BufferedInputStream bufferedResourceStream = null;
    try {
        // Make sure the stream is buffered
        if (resourceStream instanceof BufferedInputStream) {
            bufferedResourceStream = (BufferedInputStream) resourceStream;
        } else {
            bufferedResourceStream = new BufferedInputStream(resourceStream);
        }
        // Buffer up to 100MB, bad things will happen if we bust this buffer.
        // TODO see if there is a buffered stream that will write to a file once the buffer
        // fills up
        bufferedResourceStream.mark(100 * 1024 * 1024);
        final MediaType type = getMediaType(bufferedResourceStream, archive.getFilename());
        if (MT_JAVA_ARCHIVE.equals(type)) {
            final ArchiveInputStream archiveStream = new JarArchiveInputStream(bufferedResourceStream);
            importDataArchive(archive, archiveStream, options);
        } else if (MediaType.APPLICATION_ZIP.equals(type)) {
            final ArchiveInputStream archiveStream = new ZipArchiveInputStream(bufferedResourceStream);
            importDataArchive(archive, archiveStream, options);
        } else if (MT_CPIO.equals(type)) {
            final ArchiveInputStream archiveStream = new CpioArchiveInputStream(bufferedResourceStream);
            importDataArchive(archive, archiveStream, options);
        } else if (MT_AR.equals(type)) {
            final ArchiveInputStream archiveStream = new ArArchiveInputStream(bufferedResourceStream);
            importDataArchive(archive, archiveStream, options);
        } else if (MT_TAR.equals(type)) {
            final ArchiveInputStream archiveStream = new TarArchiveInputStream(bufferedResourceStream);
            importDataArchive(archive, archiveStream, options);
        } else if (MT_BZIP2.equals(type)) {
            final CompressorInputStream compressedStream = new BZip2CompressorInputStream(bufferedResourceStream);
            importDataArchive(archive, compressedStream, options);
        } else if (MT_GZIP.equals(type)) {
            final CompressorInputStream compressedStream = new GzipCompressorInputStream(bufferedResourceStream);
            importDataArchive(archive, compressedStream, options);
        } else if (MT_PACK200.equals(type)) {
            final CompressorInputStream compressedStream = new Pack200CompressorInputStream(bufferedResourceStream);
            importDataArchive(archive, compressedStream, options);
        } else if (MT_XZ.equals(type)) {
            final CompressorInputStream compressedStream = new XZCompressorInputStream(bufferedResourceStream);
            importDataArchive(archive, compressedStream, options);
        } else {
            throw new RuntimeException("Unrecognized archive media type: " + type);
        }
    } catch (IOException e) {
        throw new RuntimeException("Could not load InputStream for resource: " + archive, e);
    } finally {
        IOUtils.closeQuietly(bufferedResourceStream);
    }
}
Also used : JarArchiveInputStream(org.apache.commons.compress.archivers.jar.JarArchiveInputStream) GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) ArArchiveInputStream(org.apache.commons.compress.archivers.ar.ArArchiveInputStream) CompressorInputStream(org.apache.commons.compress.compressors.CompressorInputStream) XZCompressorInputStream(org.apache.commons.compress.compressors.xz.XZCompressorInputStream) Pack200CompressorInputStream(org.apache.commons.compress.compressors.pack200.Pack200CompressorInputStream) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) IOException(java.io.IOException) Pack200CompressorInputStream(org.apache.commons.compress.compressors.pack200.Pack200CompressorInputStream) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) JarArchiveInputStream(org.apache.commons.compress.archivers.jar.JarArchiveInputStream) ArchiveInputStream(org.apache.commons.compress.archivers.ArchiveInputStream) CpioArchiveInputStream(org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream) ArArchiveInputStream(org.apache.commons.compress.archivers.ar.ArArchiveInputStream) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) BufferedInputStream(java.io.BufferedInputStream) MediaType(org.apache.tika.mime.MediaType) CpioArchiveInputStream(org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream) XZCompressorInputStream(org.apache.commons.compress.compressors.xz.XZCompressorInputStream)

Aggregations

TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)2 BZip2CompressorInputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream)2 GzipCompressorInputStream (org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream)2 XZCompressorInputStream (org.apache.commons.compress.compressors.xz.XZCompressorInputStream)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 ArchiveInputStream (org.apache.commons.compress.archivers.ArchiveInputStream)1 ArArchiveInputStream (org.apache.commons.compress.archivers.ar.ArArchiveInputStream)1 CpioArchiveInputStream (org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream)1 JarArchiveInputStream (org.apache.commons.compress.archivers.jar.JarArchiveInputStream)1 ZipArchiveInputStream (org.apache.commons.compress.archivers.zip.ZipArchiveInputStream)1 CompressorInputStream (org.apache.commons.compress.compressors.CompressorInputStream)1 Pack200CompressorInputStream (org.apache.commons.compress.compressors.pack200.Pack200CompressorInputStream)1 MediaType (org.apache.tika.mime.MediaType)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IProfile (org.eclipse.equinox.p2.engine.IProfile)1