Example usage for org.apache.commons.compress.compressors.snappy SnappyCompressorInputStream SnappyCompressorInputStream

List of usage examples for org.apache.commons.compress.compressors.snappy SnappyCompressorInputStream SnappyCompressorInputStream

Introduction

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

Prototype

public SnappyCompressorInputStream(final InputStream is) throws IOException 

Source Link

Document

Constructor using the default buffer size of 32k.

Usage

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

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

From source file:org.apache.jena.atlas.io.IO.java

/** Open an input stream to a file; do not mask IOExceptions. 
 * If the filename is null or "-", return System.in
 * If the filename ends in .gz, wrap in GZIPInputStream  
 * @param filename/*from  www .  j a  va  2 s.c o  m*/
 * @throws FileNotFoundException 
 * @throws IOException
 */
static public InputStream openFileEx(String filename) throws IOException, FileNotFoundException {
    if (filename == null || filename.equals("-"))
        return System.in;
    if (filename.startsWith("file:")) {
        filename = filename.substring("file:".length());
        filename = IRILib.decode(filename);
    }
    InputStream in = new FileInputStream(filename);
    String ext = FilenameUtils.getExtension(filename);
    switch (ext) {
    case "":
        return in;
    case "gz":
        return new GZIPInputStream(in);
    case "bz2":
        return new BZip2CompressorInputStream(in);
    case "sz":
        return new SnappyCompressorInputStream(in);
    }
    return in;
}

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.  j a v  a 2s  .  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.");
}