Java Unzip InputStream decompressStream(InputStream input)

Here you can find the source of decompressStream(InputStream input)

Description

decompress Stream

License

Apache License

Declaration

public static InputStream decompressStream(InputStream input) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.InputStream;

import java.io.PushbackInputStream;
import java.util.zip.GZIPInputStream;

public class Main {
    public static InputStream decompressStream(InputStream input) throws Exception {
        PushbackInputStream pb = new PushbackInputStream(input, 2); //we need a pushbackstream to look ahead
        byte[] signature = new byte[2];
        try {/*from w  w  w .  j  a  v a 2  s.  co  m*/
            pb.read(signature); //read the signature
            pb.unread(signature); //push back the signature to the stream
        } catch (Exception e) {

        }
        if (signature[0] == (byte) 0x1f && signature[1] == (byte) 0x8b) //check if matches standard gzip maguc number
            return new GZIPInputStream(pb);
        else
            return pb;
    }
}

Related

  1. decompress(final int type, final InputStream is, final OutputStream os)
  2. decompress(InputStream input, File destDir)
  3. decompress(InputStream inputStream)
  4. decompress(InputStream is, OutputStream os)
  5. decompressFile(InputStream is, OutputStream os)
  6. decompressZipArchive(final File zipFile, final File rootDirectoryToUnZip)
  7. unzip(InputStream from, String to, String pattern)
  8. unzip(InputStream in)
  9. unzip(InputStream in, File destination)