Example usage for org.apache.commons.compress.archivers.zip ZipArchiveEntry getName

List of usage examples for org.apache.commons.compress.archivers.zip ZipArchiveEntry getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Get the name of the entry.

Usage

From source file:uk.nhs.cfh.dsp.srth.distribution.FileDownloader.java

private void extractZipFileContents(File file) {
    Enumeration entries;/*www .  j  a  va 2s. c  o m*/

    try {
        logger.info("Extracting zip file contents...");
        ZipFile zipFile = new ZipFile(file);

        entries = zipFile.getEntries();

        while (entries.hasMoreElements()) {
            ZipArchiveEntry entry = (ZipArchiveEntry) entries.nextElement();

            if (entry.isDirectory()) {

                logger.info("Extracting directory: " + entry.getName());
                File dir = new File(file.getParent(), entry.getName());
                boolean canWrite = dir.exists();
                if (!canWrite) {
                    canWrite = dir.mkdir();
                }

                if (canWrite) {
                    continue;
                } else {
                    logger.warning("Error creating directory during extraction");
                }
            }

            logger.info("Extracting file: " + entry.getName());
            copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(
                    new FileOutputStream(new File(file.getParent(), entry.getName()))));
        }

        zipFile.close();
        logger.info("Closed zip file.");
    } catch (IOException e) {
        logger.warning("Nested exception is : " + e.fillInStackTrace());
    }
}