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

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

Introduction

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

Prototype

public FramedSnappyCompressorInputStream(final InputStream in) throws IOException 

Source Link

Document

Constructs a new input stream that decompresses snappy-framed-compressed data from the specified input stream using the FramedSnappyDialect#STANDARD dialect.

Usage

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

/**
 * @param stream the stream to read from, should be buffered
 *//*from   ww  w  .java2  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.druid.java.util.common.CompressionUtils.java

/**
 * Decompress an input stream from a file, based on the filename.
 *//* ww  w.  jav a 2 s  . co m*/
public static InputStream decompress(final InputStream in, final String fileName) throws IOException {
    if (fileName.endsWith(GZ_SUFFIX)) {
        return gzipInputStream(in);
    } else if (fileName.endsWith(BZ2_SUFFIX)) {
        return new BZip2CompressorInputStream(in, true);
    } else if (fileName.endsWith(XZ_SUFFIX)) {
        return new XZCompressorInputStream(in, true);
    } else if (fileName.endsWith(SNAPPY_SUFFIX)) {
        return new FramedSnappyCompressorInputStream(in);
    } else if (fileName.endsWith(ZSTD_SUFFIX)) {
        return new ZstdCompressorInputStream(in);
    } else if (fileName.endsWith(ZIP_SUFFIX)) {
        // This reads the first file in the archive.
        final ZipInputStream zipIn = new ZipInputStream(in, StandardCharsets.UTF_8);
        try {
            final ZipEntry nextEntry = zipIn.getNextEntry();
            if (nextEntry == null) {
                zipIn.close();

                // No files in the archive - return an empty stream.
                return new ByteArrayInputStream(new byte[0]);
            }
            return zipIn;
        } catch (IOException e) {
            try {
                zipIn.close();
            } catch (IOException e2) {
                e.addSuppressed(e2);
            }
            throw e;
        }
    } else {
        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   www.  j a v  a 2  s .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.");
}

From source file:org.gradle.caching.internal.tasks.SnappyCommonsPacker.java

@Override
public void unpack(DataSource input, DataTargetFactory targetFactory) throws IOException {
    delegate.unpack(new DelegatingDataSource(input) {
        @Override//from  w w  w  .j a  v  a2s.co  m
        public InputStream openInput() throws IOException {
            return new FramedSnappyCompressorInputStream(super.openInput());
        }
    }, targetFactory);
}