Example usage for org.apache.commons.compress.archivers ArchiveStreamFactory ArchiveStreamFactory

List of usage examples for org.apache.commons.compress.archivers ArchiveStreamFactory ArchiveStreamFactory

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers ArchiveStreamFactory ArchiveStreamFactory.

Prototype

ArchiveStreamFactory

Source Link

Usage

From source file:uk.ac.ebi.metabolights.utils.Zipper.java

public static void unzip2(String strZipFile, String folder) throws IOException, ArchiveException {

    //Check if the file exists
    FileUtil.fileExists(strZipFile, true);

    final InputStream is = new FileInputStream(strZipFile);
    ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream("zip", is);

    ZipArchiveEntry entry = null;/*from w  w w  .j a v a2 s .  c o m*/
    OutputStream out = null;

    while ((entry = (ZipArchiveEntry) in.getNextEntry()) != null) {

        //create directories if required.
        File zipPath = new File(folder);
        File destinationFilePath = new File(zipPath, entry.getName());
        destinationFilePath.getParentFile().mkdirs();

        //if the entry is directory, leave it. Otherwise extract it.
        if (entry.isDirectory()) {
            continue;
        } else {
            out = new FileOutputStream(new File(folder, entry.getName()));
            IOUtils.copy(in, out);
            out.close();
        }

    }

    in.close();

}

From source file:uk.ac.ebi.metabolights.webservice.utils.Zipper.java

public static void unzip2(String strZipFile, String folder) throws IOException, ArchiveException {

    // Remove any previous content of the unzip folder.
    File uf = new File(folder);
    FileUtil.deleteDir(uf);/*from   ww  w . j  a  v a  2 s.  c o m*/
    // Create it again, this time it will be empty..
    uf.mkdir();

    //Check if the file exists
    FileUtil.fileExists(strZipFile, true);

    final InputStream is = new FileInputStream(strZipFile);
    ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream("zip", is);

    ZipArchiveEntry entry = null;
    OutputStream out = null;

    while ((entry = (ZipArchiveEntry) in.getNextEntry()) != null) {

        //create directories if required.
        File zipPath = new File(folder);
        File destinationFilePath = new File(zipPath, entry.getName());
        destinationFilePath.getParentFile().mkdirs();

        //if the entry is directory, leave it. Otherwise extract it.
        if (entry.isDirectory()) {
            continue;
        } else {
            out = new FileOutputStream(new File(folder, entry.getName()));
            IOUtils.copy(in, out);
            out.close();
        }

    }

    in.close();

}