Examples of ZipFile


Examples of org.apache.tools.zip.ZipFile

        }

        AtomicBoolean stopFlag = new AtomicBoolean();

        try {
            ZipFile zip = new ZipFile(zipFile);
            try {
                // The iteration order of zip.getEntries() is based on the hash of the zip entry. This isn't much use
                // to us. So, collect the entries in a map and iterate over them in alphabetical order.
                Map<String, ZipEntry> entriesByName = new TreeMap<String, ZipEntry>();
                Enumeration entries = zip.getEntries();
                while (entries.hasMoreElements()) {
                    ZipEntry entry = (ZipEntry) entries.nextElement();
                    entriesByName.put(entry.getName(), entry);
                }
                Iterator<ZipEntry> sortedEntries = entriesByName.values().iterator();
                while (!stopFlag.get() && sortedEntries.hasNext()) {
                    ZipEntry entry = sortedEntries.next();
                    if (entry.isDirectory()) {
                        visitor.visitDir(new DetailsImpl(entry, zip, stopFlag));
                    } else {
                        visitor.visitFile(new DetailsImpl(entry, zip, stopFlag));
                    }
                }
            } finally {
                zip.close();
            }
        } catch (Exception e) {
            throw new GradleException(String.format("Could not expand %s.", this), e);
        }
View Full Code Here

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

Examples of org.codehaus.plexus.archiver.zip.ZipFile

     */
    protected static final void grabFilesAndDirs( String file, List dirs,
                                                  List files )
        throws IOException
    {
        ZipFile zf = null;
        try
        {
            zf = new ZipFile( file, "utf-8" );
            Enumeration entries = zf.getEntries();
            HashSet dirSet = new HashSet();
            while ( entries.hasMoreElements() )
            {
                ZipEntry ze =
                    (ZipEntry) entries.nextElement();
                String name = ze.getName();
                // META-INF would be skipped anyway, avoid index for
                // manifest-only jars.
                if ( !name.startsWith( "META-INF/" ) )
                {
                    if ( ze.isDirectory() )
                    {
                        dirSet.add( name );
                    }
                    else if ( name.indexOf( "/" ) == -1 )
                    {
                        files.add( name );
                    }
                    else
                    {
                        // a file, not in the root
                        // since the jar may be one without directory
                        // entries, add the parent dir of this file as
                        // well.
                        dirSet.add( name.substring( 0,
                                                    name.lastIndexOf( "/" ) + 1 ) );
                    }
                }
            }
            dirs.addAll( dirSet );
        }
        finally
        {
            if ( zf != null )
            {
                zf.close();
            }
        }
    }
View Full Code Here
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.