Package java.util.zip

Examples of java.util.zip.ZipFile


        this.name2ids  = new TreeMap<String, List<Integer>>(insensitiveCollator);
       
        if (file == null || !file.exists()) return;
        BufferedReader reader;
        try {
            ZipFile zf = new ZipFile(file);
            ZipEntry ze = zf.getEntry("cities1000.txt");
            InputStream is = zf.getInputStream(ze);
            reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        } catch (IOException e) {
            Log.logException(e);
            return;
        }
View Full Code Here


            for (int i = 0; i < files.length; ++i) {
                optimize(files[i]);
            }
        } else if (f.getName().endsWith(".jar")) {
            File g = new File(f.getParentFile(), f.getName() + ".new");
            ZipFile zf = new ZipFile(f);
            ZipOutputStream out = new ZipOutputStream(new FileOutputStream(g));
            Enumeration<? extends ZipEntry> e = zf.entries();
            byte[] buf = new byte[10000];
            while (e.hasMoreElements()) {
                ZipEntry ze = e.nextElement();
                if (ze.isDirectory()) {
                    continue;
                }
                out.putNextEntry(ze);
                if (ze.getName().endsWith(".class")) {
                    ClassReader cr = new ClassReader(zf.getInputStream(ze));
                    // cr.accept(new ClassDump(), 0);
                    cr.accept(new ClassVerifier(), 0);
                }
                InputStream is = zf.getInputStream(ze);
                int n;
                do {
                    n = is.read(buf, 0, buf.length);
                    if (n != -1) {
                        out.write(buf, 0, n);
                    }
                } while (n != -1);
                out.closeEntry();
            }
            out.close();
            zf.close();
            if (!f.delete()) {
                throw new IOException("Cannot delete file " + f);
            }
            if (!g.renameTo(f)) {
                throw new IOException("Cannot rename file " + g);
View Full Code Here

* @author Eric Bruneton
*/
public class Performances {

  public static void main(String[] args) throws Exception {
    ZipFile zip = new ZipFile(args[0]);
    String clazz = args.length > 1 ? args[1] : null;

    List classes = new ArrayList();
    Enumeration entries = zip.entries();
    while (entries.hasMoreElements()) {
      ZipEntry e = (ZipEntry) entries.nextElement();
      String s = e.getName();
      if (s.endsWith(".class")) {
        s = s.substring(0, s.length() - 6).replace('/', '.');
        if (clazz == null || s.indexOf(clazz) != -1) {
          InputStream is = zip.getInputStream(e);
          classes.add(new ClassReader(is).b);
        }
      }
    }

View Full Code Here

                System.getProperty("java.class.path")));
        repeats = Integer.getInteger("repeats", 3).intValue() + 1;

        Set<String> classesFound = new HashSet<String>();
        for (int i = 0; i < jars.size(); i++) {
            ZipFile zip;
            try {
                zip = new ZipFile(jars.get(i));
            } catch (IOException e) {
                System.err.println("Error openning " + jars.get(i));
                e.printStackTrace();
                continue;
            }

            Enumeration<? extends ZipEntry> entries = zip.entries();
            while (entries.hasMoreElements()) {
                ZipEntry e = entries.nextElement();
                String s = e.getName();
                if (s.endsWith(".class")) {
                    s = s.substring(0, s.length() - 6).replace('/', '.');
                    if (!classesFound.add(s)) {
                        continue;
                    }
                    if (clazz == null || s.indexOf(clazz) != -1) {
                        InputStream is = zip.getInputStream(e);
                        byte[] bytes = new ClassReader(is).b;
                        classes.add(bytes);
                        classNames.add(s);
                        is.close();
                        if (classes.size() % 2500 == 0) {
                            System.out.println("... searching, found "
                                    + classes.size() + " classes.");
                        }
                    }
                }
            }
            zip.close();
        }
        System.out.println("Found " + classes.size() + " classes.");

        RunTest nullBCELAdapt = new RunTest() {
            @Override
View Full Code Here

     */
    private List<Runner> createRunners(String archivePath) throws InitializationError
    {
        List<Runner> list = new ArrayList<Runner>();
        try {
            final ZipFile archive = new ZipFile(archivePath);
            Enumeration< ? extends ZipEntry> entries = archive.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                if (entry.isDirectory()) {
                    continue;
                }
                Reader reader = new InputStreamReader(archive.getInputStream(entry));
                addTest(list, entry.getName(), reader);
            }
            archive.close();
        } catch (IOException exception) {
            throw new InitializationError(exception);
        }
        return list;
    }
View Full Code Here

        flgResult = true;
        logger.debug(String.format("Zip-File '%1$s' created", pstrPathName));
      }
      else {
        if (objFile.exists()) {
          objWorkingDirectory = new ZipFile(objFile, ZipFile.OPEN_READ);
          flgResult = true;
          logger.debug(String.format("Zip-File '%1$s' opened", pstrPathName));
        }
      }
    }
View Full Code Here

    }
  }

  private static void unzipWrapper(String destination, String zipFileName) throws IOException, IOException
  {
    ZipFile zipFile = new ZipFile(zipFileName);

    Enumeration<? extends ZipEntry> entries = zipFile.entries();

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

      if (entry.isDirectory())
      {
        // Assume directories are stored parents first then children.
        System.err.println("Extracting wrapper folder: " + entry.getName());
        // This is not robust, just for demonstration purposes.
        (new File(destination + "/" + entry.getName())).mkdir();
        continue;
      }

      if (entry.getName().endsWith("wrapper.jar"))
        _wrapperJar = destination + "/" + entry.getName();
      // skip java source file
      if (entry.getName().endsWith(".java"))
        continue;
      System.err.println("Extracting wrapper file: " + entry.getName());
      BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(destination + "/" + entry.getName()));
      copyStream(new BufferedInputStream(zipFile.getInputStream(entry)), out);
      out.close();
    }
    zipFile.close();
  }
View Full Code Here

  }

  private static String getManifest(String destination) throws IOException
  {
    ZipFile z = new ZipFile(destination + "/wrapper.jar");
    ZipEntry ze = z.getEntry("META-INF/MANIFEST.MF");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    BufferedInputStream in = new BufferedInputStream(z.getInputStream(ze));
    byte data[] = new byte[1024];
    int count = 0;
    while ((count = in.read(data, 0, 1024)) != -1)
    {
      out.write(data, 0, count);
    }
    in.close();
    z.close();
    return new String(out.toByteArray()).replaceAll("\r\n ", "");
  }
View Full Code Here

        ZipInputStream zis = null;
        InputStream is = null;

        byte[] buffer = new byte[16 * 1024];

        ZipFile zipFile = null;
        try {
            is = new BufferedInputStream(new FileInputStream(archive));
            zipFile = new ZipFile(archive);
            zis = new ZipInputStream(is);
            while (true) {
                ZipEntry entry = zis.getNextEntry();
                if (entry == null) {
                    break;
                }
                if (entry.isDirectory() || !entryName.equals(entry.getName())) {
                    zis.closeEntry();
                    continue;
                }
                InputStream fis = null;
                OutputStream fos = null;
                try {
                    fis = new BufferedInputStream(zipFile.getInputStream(entry));
                    fos = new BufferedOutputStream(new FileOutputStream(to));
                    while (true) {
                        int r = fis.read(buffer);
                        if (r < 0) {
                            break;
                        } else if (r == 0) {
                            continue;
                        }
                        fos.write(buffer, 0, r);
                    }
                } finally {
                    if (fos != null) {
                        try {
                            fos.close();
                        } catch (IOException e) {
                        }
                    }
                    if (fis != null) {
                        try {
                            fis.close();
                        } catch (IOException e) {
                        }
                    }
                }
                if (deleteCopy) {
                    to.deleteOnExit();
                }
                zis.closeEntry();
                break;
            }
        } finally {
            if (zis != null) {
                try {
                    zis.close();
                } catch (IOException e) {
                }
            }
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                }
            }
            if (zipFile != null) {
                try {
                    zipFile.close();
                } catch (IOException e) {
                }
            }
        }
    }
View Full Code Here

 
  public ZippedDirectory(SystemFile file) {
    super(null, new SimplePath(""), "");
    this.realFile = file;
    try {
      this.zipFile = new ZipFile(file.getRealArtifact());
    } catch (ZipException e) {
      throw ThrowableManagerRegistry.caught(e);
    } catch (IOException e) {
      throw ThrowableManagerRegistry.caught(e);
    }
View Full Code Here

TOP

Related Classes of java.util.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.