Android InputStream Unzip unzip(InputStream fileIn, File dirOut)

Here you can find the source of unzip(InputStream fileIn, File dirOut)

Description

This is not tested on hierarchical zip files, currently only used on flat archives

License

Open Source License

Parameter

Parameter Description
fileIn a parameter
dirOut a parameter

Return

true on success

Declaration

public static boolean unzip(InputStream fileIn, File dirOut) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.util.Log;

import java.io.File;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
    /**/*from  w  w w.j a  v a 2 s.  c o  m*/
     * This is not tested on hierarchical zip files, currently only used on flat archives
     * @param fileIn
     * @param dirOut
     * @return true on success
     */
    public static boolean unzip(InputStream fileIn, File dirOut) {
        try {
            ZipInputStream zin = new ZipInputStream(fileIn);
            ZipEntry ze = null;
            while ((ze = zin.getNextEntry()) != null) {
                Log.v("Decompress", "Unzipping " + ze.getName());
                if (ze.isDirectory()) {
                    throw new UnsupportedOperationException(
                            "currently only flat archives are supported");
                } else {
                    FileOutputStream fout = new FileOutputStream(new File(
                            dirOut, ze.getName()));
                    for (int c = zin.read(); c != -1; c = zin.read()) {
                        fout.write(c);
                    }
                    zin.closeEntry();
                    fout.close();
                }
            }
            zin.close();
            return true;
        } catch (Exception e) {
            Log.e("Decompress", "unzip", e);
            return false;
        }
    }
}

Related

  1. unZip(InputStream in, String destDir)
  2. unZip(InputStream is, String filename, String folderPath)
  3. unpackZip(InputStream zipStream, String unpackPath)
  4. decompress(InputStream is, OutputStream os)
  5. decompress(InputStream is, OutputStream os)
  6. decompress(InputStream is, OutputStream os)
  7. uncompress(InputStream inputStream)