Example usage for org.apache.commons.compress.compressors CompressorException CompressorException

List of usage examples for org.apache.commons.compress.compressors CompressorException CompressorException

Introduction

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

Prototype

public CompressorException(String message, Throwable cause) 

Source Link

Document

Constructs a new exception with the specified detail message and cause.

Usage

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

/**
 * Try to detect the type of compressor stream.
 *
 * @param in input stream/*from w ww  .j ava2  s.c o m*/
 * @return type of compressor stream detected
 * @throws CompressorException if no compressor stream type was detected
 *                             or if something else went wrong
 * @throws IllegalArgumentException if stream is null or does not support mark
 *
 * @since 1.14
 */
public static String detect(final InputStream in) throws CompressorException {
    if (in == null) {
        throw new IllegalArgumentException("Stream must not be null.");
    }

    if (!in.markSupported()) {
        throw new IllegalArgumentException("Mark is not supported.");
    }

    final byte[] signature = new byte[12];
    in.mark(signature.length);
    int signatureLength = -1;
    try {
        signatureLength = IOUtils.readFully(in, signature);
        in.reset();
    } catch (IOException e) {
        throw new CompressorException("IOException while reading signature.", e);
    }

    if (BZip2CompressorInputStream.matches(signature, signatureLength)) {
        return BZIP2;
    }

    if (GzipCompressorInputStream.matches(signature, signatureLength)) {
        return GZIP;
    }

    if (Pack200CompressorInputStream.matches(signature, signatureLength)) {
        return PACK200;
    }

    if (FramedSnappyCompressorInputStream.matches(signature, signatureLength)) {
        return SNAPPY_FRAMED;
    }

    if (ZCompressorInputStream.matches(signature, signatureLength)) {
        return Z;
    }

    if (DeflateCompressorInputStream.matches(signature, signatureLength)) {
        return DEFLATE;
    }

    if (XZUtils.matches(signature, signatureLength)) {
        return XZ;
    }

    if (LZMAUtils.matches(signature, signatureLength)) {
        return LZMA;
    }

    /*            if (FramedLZ4CompressorInputStream.matches(signature, signatureLength)) {
        return LZ4_FRAMED;
    }*/

    throw new CompressorException("No Compressor found for the stream signature.");
}

From source file:org.jgrades.backup.creator.ZipUtils.java

public void zipFiles(String srcFolder, String destZipFile) throws CompressorException {
    try {/*from  ww  w .j a v  a 2s .co  m*/
        zipFolder(srcFolder, destZipFile);
    } catch (Exception e) {
        throw new CompressorException("Zipping files failed", e);
    }
}