Package org.beangle.commons.archiver.zip

Examples of org.beangle.commons.archiver.zip.ZipFile


    String dest = destination;
    if (!destination.endsWith(File.separator)) {
      dest = destination + File.separator;
    }

    ZipFile zf = null;
    try {
      zf = new ZipFile(zipFile);
      @SuppressWarnings("unchecked")
      Enumeration<ZipEntry> enu = zf.getEntries();
      while (enu.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) enu.nextElement();
        String name = entry.getName();
        String path = dest + name;
        File file = new File(path);
        if (entry.isDirectory()) {
          file.mkdirs();
        } else {
          InputStream is = zf.getInputStream(entry);
          byte[] buf1 = new byte[1024];
          int len;
          if (!file.exists()) {
            file.getParentFile().mkdirs();
            file.createNewFile();
          }
          OutputStream out = new FileOutputStream(file);
          while ((len = is.read(buf1)) > 0) {
            out.write(buf1, 0, len);
          }
          out.flush();
          out.close();
          is.close();
          fileNames.add(file.getAbsolutePath());
        }
      }
      zf.close();
    } catch (Exception e) {
      throw new RuntimeException(e);
    } finally {
      if (null != zf) {
        try {
          zf.close();
        } catch (IOException e) {
        }
      }
    }
    return fileNames;
View Full Code Here


    }
  }

  public static boolean isZipFile(File zipFile) {
    try {
      ZipFile zf = new ZipFile(zipFile);
      boolean isZip = zf.getEntries().hasMoreElements();
      zf.close();
      return isZip;
    } catch (ZipException e) {
      return false;
    } catch (Exception e) {
      return false;
View Full Code Here

TOP

Related Classes of org.beangle.commons.archiver.zip.ZipFile

Copyright © 2018 www.massapicom. 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.