/*
 * Created on 2004/11/05
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.jware.util.crypt;

import java.io.*;
import java.util.ArrayList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
 * @author jrmt
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Unzip implements Serializable{

    static final int BUFFER_SIZE = 2048;
    /**
     * 
     */
    public Unzip() {
        super();
    }

    public static ArrayList unzip(String zipfilename, String outbase)
    {
        System.out.println("unzip: " + zipfilename);
        System.out.println("unzip: " + outbase);
        File f = new File(outbase);
        if(!f.exists())
            f.mkdirs();
        ArrayList filenames = new ArrayList();
        try
        {
            BufferedOutputStream dest = null;
            FileInputStream fis = new FileInputStream(zipfilename);
            ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
            ZipEntry entry;
            while((entry = zis.getNextEntry()) != null) 
            {
                byte data[] = new byte[BUFFER_SIZE];
                String en = entry.getName();
                en = outbase + File.separator + en;
                filenames.add(en);
                FileOutputStream fos = new FileOutputStream(en);
                dest = new BufferedOutputStream(fos, BUFFER_SIZE);
                int count;
                while((count = zis.read(data, 0, BUFFER_SIZE)) != -1) 
                    dest.write(data, 0, count);
                dest.flush();
                dest.close();
            }
            zis.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return filenames;
    }

}
