Package com.opensymphony.webwork.portlet.util

Source Code of com.opensymphony.webwork.portlet.util.FileUnzipper

package com.opensymphony.webwork.portlet.util;


import java.io.File;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import com.opensymphony.util.TextUtils;

//Referenced classes of package com.atlassian.confluence.util:
//       AbstractUnzipper

public class FileUnzipper extends AbstractUnzipper {
  private File zipFile;

  public FileUnzipper(File zipFile, File destDir) {
      this.zipFile = zipFile;
      super.destDir = destDir;
  }

  public void unzip() throws Exception {
      if (zipFile == null || !zipFile.isFile())
          return;
      ZipFile zf = new ZipFile(zipFile);
      ZipEntry zipEntry;
      for (Enumeration zipEntries = zf.entries(); zipEntries.hasMoreElements(); saveEntry(
              zf.getInputStream(zipEntry), zipEntry))
          zipEntry = (ZipEntry) zipEntries.nextElement();

      zf.close();
  }

  public File unzipFileInArchive(String fileName) throws Exception {
      File result = null;
      if (zipFile == null || !zipFile.isFile() || !TextUtils.stringSet(fileName))
          return result;
      boolean fileFound = false;
      ZipFile zf = new ZipFile(zipFile);
      Enumeration zipEntries = zf.entries();
      do {
          if (!zipEntries.hasMoreElements())
              break;
          ZipEntry entry = (ZipEntry) zipEntries.nextElement();
          String entryName = entry.getName();
          if (TextUtils.stringSet(entryName) && entryName.startsWith("/"))
              entryName = entryName.substring(1);
          if (fileName.equals(entryName)) {
              fileFound = true;
              result = saveEntry(zf.getInputStream(entry), entry);
          }
      } while (true);
      if (!fileFound)
          AbstractUnzipper.log.error("The file: " + fileName + " could not be found in the archive: "
                  + zipFile.getAbsolutePath());
      zf.close();
      return result;
  }

}
TOP

Related Classes of com.opensymphony.webwork.portlet.util.FileUnzipper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.