Example usage for org.apache.commons.compress.compressors.pack200 Pack200CompressorInputStream Pack200CompressorInputStream

List of usage examples for org.apache.commons.compress.compressors.pack200 Pack200CompressorInputStream Pack200CompressorInputStream

Introduction

In this page you can find the example usage for org.apache.commons.compress.compressors.pack200 Pack200CompressorInputStream Pack200CompressorInputStream.

Prototype

public Pack200CompressorInputStream(final File f) throws IOException 

Source Link

Document

Decompresses the given file, caching the decompressed data in memory.

Usage

From source file:org.apache.ant.compress.util.Pack200StreamFactory.java

/**
 * @param stream the stream to read from, should be buffered
 *//*from   w  w  w  . j  a  v  a 2 s . c o m*/
public CompressorInputStream getCompressorStream(InputStream stream) throws IOException {
    return new Pack200CompressorInputStream(stream);
}

From source file:org.apache.ant.compress.util.Pack200StreamFactory.java

/**
 * @param file the file to read from/*from   ww  w.  java  2 s.c om*/
 */
public CompressorInputStream getCompressorInputStream(File file) throws IOException {
    return new Pack200CompressorInputStream(file);
}

From source file:org.apache.tika.parser.pkg.TikaCompressorStreamFactory.java

public CompressorInputStream createCompressorInputStream(final String name, final InputStream in,
        final boolean actualDecompressConcatenated) throws CompressorException {
    if (name == null || in == null) {
        throw new IllegalArgumentException("Compressor name and stream must not be null.");
    }/*from  w  w  w .  ja  va2  s.c o m*/

    try {

        if (GZIP.equalsIgnoreCase(name)) {
            return new GzipCompressorInputStream(in, actualDecompressConcatenated);
        }

        if (BZIP2.equalsIgnoreCase(name)) {
            return new BZip2CompressorInputStream(in, actualDecompressConcatenated);
        }

        if (XZ.equalsIgnoreCase(name)) {
            if (!XZUtils.isXZCompressionAvailable()) {
                throw new CompressorException("XZ compression is not available.");
            }
            return new XZCompressorInputStream(in, actualDecompressConcatenated);
        }

        if (LZMA.equalsIgnoreCase(name)) {
            if (!LZMAUtils.isLZMACompressionAvailable()) {
                throw new CompressorException("LZMA compression is not available");
            }
            try {
                return new SaferLZMACompressorInputStream(in);
            } catch (MemoryLimitException e) {
                throw new CompressorException("MemoryLimitException: " + e.getMessage(), e);
            }
        }

        if (PACK200.equalsIgnoreCase(name)) {
            return new Pack200CompressorInputStream(in);
        }

        if (SNAPPY_RAW.equalsIgnoreCase(name)) {
            return new SnappyCompressorInputStream(in);
        }

        if (SNAPPY_FRAMED.equalsIgnoreCase(name)) {
            return new FramedSnappyCompressorInputStream(in);
        }

        if (Z.equalsIgnoreCase(name)) {
            try {
                return new SaferZCompressorInputStream(in);
            } catch (TikaRuntimeMemoryLimitException e) {
                throw new CompressorException("MemoryLimitException: " + e.getMessage(), e);
            }
        }

        if (DEFLATE.equalsIgnoreCase(name)) {
            return new DeflateCompressorInputStream(in);
        }
        /*
        not currently supported
        if (LZ4_BLOCK.equalsIgnoreCase(name)) {
            return new BlockLZ4CompressorInputStream(in);
        }
                
        if (LZ4_FRAMED.equalsIgnoreCase(name)) {
            return new FramedLZ4CompressorInputStream(in, actualDecompressConcatenated);
        }
         */

    } catch (final IOException e) {
        throw new CompressorException("Could not create CompressorInputStream.", e);
    }

    final CompressorStreamProvider compressorStreamProvider = getCompressorInputStreamProviders()
            .get(toKey(name));
    if (compressorStreamProvider != null) {
        return compressorStreamProvider.createCompressorInputStream(name, in, actualDecompressConcatenated);
    }

    throw new CompressorException("Compressor: " + name + " not found.");
}

From source file:org.apereo.portal.io.xml.JaxbPortalDataHandlerService.java

protected void importDataArchive(Resource archive, InputStream resourceStream, BatchImportOptions options) {
    BufferedInputStream bufferedResourceStream = null;
    try {//w  w w  .  j a  v a  2 s.  co  m
        //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);
    }
}