Java Unzip to Folder unzip(String path, int buffer)

Here you can find the source of unzip(String path, int buffer)

Description

unzip

License

Open Source License

Declaration

public static InputStream unzip(String path, int buffer) 

Method Source Code

//package com.java2s;
/**//from ww w  . j av  a2s. c  o m
 * 
 * @author Thomas Asikis
 * @license Copyright (c) 2016 Thomas Asikis
 *         Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *          The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *          THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import java.io.BufferedInputStream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.InputStream;

import java.io.UnsupportedEncodingException;

import java.util.Enumeration;

import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {
    public static InputStream unzip(String path, int buffer) {
        ZipFile zipfile;
        try {
            zipfile = new ZipFile(path);
            Enumeration<? extends ZipEntry> e = zipfile.entries();
            BufferedInputStream is = null;
            ZipEntry entry;

            while (e.hasMoreElements()) {
                entry = (ZipEntry) e.nextElement();
                System.out.println("Extracting: " + entry);
                is = new BufferedInputStream(zipfile.getInputStream(entry));
                return is;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    public static InputStream getInputStream(String path)
            throws UnsupportedEncodingException, FileNotFoundException {
        return new FileInputStream(path);
    }
}

Related

  1. unzip(String file, String destinationdir)
  2. unzip(String filePath, String unzipPath)
  3. unzip(String inFilePath)
  4. unzip(String inFilePath, String outFilePath)
  5. unzip(String inputZipPath, String destinationDirectory)
  6. unZip(String pathDest, BufferedInputStream buffInputStream)
  7. unzip(String sourceFile, String destDir)
  8. unzip(String sourceFile, String destDir)
  9. unzip(String sourceFile, String toDir)