Example usage for org.apache.commons.compress.compressors.xz XZUtils isXZCompressionAvailable

List of usage examples for org.apache.commons.compress.compressors.xz XZUtils isXZCompressionAvailable

Introduction

In this page you can find the example usage for org.apache.commons.compress.compressors.xz XZUtils isXZCompressionAvailable.

Prototype

public static boolean isXZCompressionAvailable() 

Source Link

Document

Are the classes required to support XZ compression available?

Usage

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.");
    }/* w w w .ja v  a 2s. co  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.");
}