Java Unzip InputStream unzip(InputStream in)

Here you can find the source of unzip(InputStream in)

Description

unzip

License

Apache License

Declaration

public static byte[] unzip(InputStream in) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *
 *==============================================================================
 *
 * Copyright (c) 2008-2011 ayound@gmail.com
 * This program and the accompanying materials
 * are made available under the terms of the Apache License 2.0
 * which accompanies this distribution, and is available at
 * http://www.apache.org/licenses/LICENSE-2.0
 * All rights reserved./*  ww w.ja v a 2 s .  c o m*/
 *
 * Created on 2009-3-27
 *******************************************************************************/

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;

public class Main {
    public static byte[] unzip(InputStream in) throws IOException {
        // Open the compressed stream
        GZIPInputStream gin = new GZIPInputStream(in);

        ByteArrayOutputStream out = new ByteArrayOutputStream();

        // Transfer bytes from the compressed stream to the output stream
        byte[] buf = new byte[1024];
        int len;
        while ((len = gin.read(buf)) > 0) {
            out.write(buf, 0, len);
        }

        // Close the file and stream
        gin.close();
        out.close();
        return out.toByteArray();
    }
}

Related

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