Package java.util.zip

Examples of java.util.zip.ZipFile


    return null;
  }
  return null;
}
public void initialize() throws IOException {
  this.zipFile = new ZipFile(this.file);
}
View Full Code Here


private void ensureOpen() throws IOException {
  if (zipFile != null) return; // If its not null, the zip is already open
  if (openArchives.size()>=maxOpenArchives) {
    closeSomeArchives(openArchives.size()/10); // Close 10% of those open
  }
  zipFile = new ZipFile(file);
  openArchives.add(this);
}
View Full Code Here

    // if (lowercaseClasspathName.endsWith(SUFFIX_STRING_jar)
    //  || lowercaseClasspathName.endsWith(SUFFIX_STRING_zip)) {
    // new code:
    boolean isZip = false;
    try {
      ZipFile zf = new ZipFile(file);
      zf.close();
      isZip = true;
    } catch (Exception e) {
      // this means it is not a valid Zip
    }
    if (isZip) {
View Full Code Here

   * @exception CoreException If unable to create/open the ZipFile
   */
  public ZipFile getZipFile(IPath path) throws CoreException {
     
    HashMap map;
    ZipFile zipFile;
    if ((map = (HashMap)this.zipFiles.get()) != null
        && (zipFile = (ZipFile)map.get(path)) != null) {
       
      return zipFile;
    }
    File localFile = null;
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IResource file = root.findMember(path);
    if (file != null) {
      // internal resource
      URI location;
      if (file.getType() != IResource.FILE || (location = file.getLocationURI()) == null) {
        throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.bind(Messages.file_notFound, path.toString()), null));
      }
      localFile = Util.toLocalFile(location, null/*no progress availaible*/);
      if (localFile == null)
        throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.bind(Messages.file_notFound, path.toString()), null));
    } else {
      // external resource -> it is ok to use toFile()
      localFile= path.toFile();
    }

    try {
      if (ZIP_ACCESS_VERBOSE) {
        System.out.println("(" + Thread.currentThread() + ") [JavaModelManager.getZipFile(IPath)] Creating ZipFile on " + localFile ); //$NON-NLS-1$ //$NON-NLS-2$
      }
      zipFile = new ZipFile(localFile);
      if (map != null) {
        map.put(path, zipFile);
      }
      return zipFile;
    } catch (IOException e) {
View Full Code Here

    if (map == null) return;
    this.zipFiles.set(null);
    Iterator iterator = map.values().iterator();
    while (iterator.hasNext()) {
      try {
        ZipFile zipFile = (ZipFile)iterator.next();
        if (JavaModelManager.ZIP_ACCESS_VERBOSE) {
          System.out.println("(" + currentThread + ") [JavaModelManager.flushZipFiles()] Closing ZipFile on " +zipFile.getName()); //$NON-NLS-1$//$NON-NLS-2$
        }
        zipFile.close();
      } catch (IOException e) {
        // problem occured closing zip file: cannot do much more
      }
    }
  }
View Full Code Here

      throw new BuildException(AntAdapterMessages.getString("checkDebugAttributes.property.argument.cannot.be.null")); //$NON-NLS-1$
    }
    try {
      boolean hasDebugAttributes = false;
      if (org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(this.file)) {
        ZipFile jarFile = new ZipFile(this.file);
        for (Enumeration entries = jarFile.entries(); !hasDebugAttributes && entries.hasMoreElements(); ) {
          ZipEntry entry = (ZipEntry) entries.nextElement();
          if (org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entry.getName())) {
            IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(this.file, entry.getName(), IClassFileReader.ALL);
            hasDebugAttributes = checkClassFile(classFileReader);
          }
View Full Code Here

   * @param decodingFlag the flag used to decode the class file reader.
   * @return a default classfile reader
   * @see IClassFileReader
   */
  public static IClassFileReader createDefaultClassFileReader(String zipFileName, String zipEntryName, int decodingFlag){
    ZipFile zipFile = null;
    try {
      if (JavaModelManager.ZIP_ACCESS_VERBOSE) {
        System.out.println("(" + Thread.currentThread() + ") [ToolFactory.createDefaultClassFileReader()] Creating ZipFile on " + zipFileName); //$NON-NLS-1$  //$NON-NLS-2$
      }
      zipFile = new ZipFile(zipFileName);
      ZipEntry zipEntry = zipFile.getEntry(zipEntryName);
      if (zipEntry == null) {
        return null;
      }
      if (!zipEntryName.toLowerCase().endsWith(SuffixConstants.SUFFIX_STRING_class)) {
        return null;
      }
      byte classFileBytes[] = Util.getZipEntryByteContent(zipEntry, zipFile);
      return new ClassFileReader(classFileBytes, decodingFlag);
    } catch(ClassFormatException e) {
      return null;
    } catch(IOException e) {
      return null;
    } finally {
      if (zipFile != null) {
        try {
          zipFile.close();
        } catch(IOException e) {
          // ignore
        }
      }
    }
View Full Code Here

    file.setParent(newParent);
    return file;
  }
 
  public InputStream getContents() throws CoreException {
    ZipFile zipFile = null;
    try {
      zipFile = getZipFile();
      if (JavaModelManager.ZIP_ACCESS_VERBOSE) {
        System.out.println("(" + Thread.currentThread() + ") [JarEntryFile.getContents()] Creating ZipFile on " +zipFile.getName()); //$NON-NLS-1$  //$NON-NLS-2$
      }
      String entryName = getEntryName();
      ZipEntry zipEntry = zipFile.getEntry(entryName);
      if (zipEntry == null){
        throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, entryName));
      }
      byte[] contents = Util.getZipEntryByteContent(zipEntry, zipFile);
      return new ByteArrayInputStream(contents);
View Full Code Here

      if (monitor == null) {
        if (JobManager.VERBOSE)
          org.aspectj.org.eclipse.jdt.internal.core.util.Util.verbose("-> index for " + this.containerPath + " just got deleted"); //$NON-NLS-1$//$NON-NLS-2$
        return true; // index got deleted since acquired
      }
      ZipFile zip = null;
      try {
        // this path will be a relative path to the workspace in case the zipfile in the workspace otherwise it will be a path in the
        // local file system
        Path zipFilePath = null;

        monitor.enterWrite(); // ask permission to write
        if (resource != null) {
          URI location = this.resource.getLocationURI();
          if (location == null) return false;
          if (JavaModelManager.ZIP_ACCESS_VERBOSE)
            System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Creating ZipFile on " + location.getPath()); //$NON-NLS-1$  //$NON-NLS-2$
          File file = null;
          try {
            file = org.aspectj.org.eclipse.jdt.internal.core.util.Util.toLocalFile(location, progressMonitor);
          } catch (CoreException e) {
            if (JobManager.VERBOSE) {
              org.aspectj.org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + location.getPath() + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
              e.printStackTrace();
            }
          }
          if (file == null) {
            if (JobManager.VERBOSE)
              org.aspectj.org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + location.getPath() + " because the file could not be fetched"); //$NON-NLS-1$ //$NON-NLS-2$
            return false;
          }
          zip = new ZipFile(file);
          zipFilePath = (Path) this.resource.getFullPath().makeRelative();
          // absolute path relative to the workspace
        } else {
          if (JavaModelManager.ZIP_ACCESS_VERBOSE)
            System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Creating ZipFile on " + this.containerPath); //$NON-NLS-1$  //$NON-NLS-2$
          // external file -> it is ok to use toFile()
          zip = new ZipFile(this.containerPath.toFile());
          zipFilePath = (Path) this.containerPath;
          // path is already canonical since coming from a library classpath entry
        }

        if (this.isCancelled) {
          if (JobManager.VERBOSE)
            org.aspectj.org.eclipse.jdt.internal.core.util.Util.verbose("-> indexing of " + zip.getName() + " has been cancelled"); //$NON-NLS-1$ //$NON-NLS-2$
          return false;
        }

        if (JobManager.VERBOSE)
          org.aspectj.org.eclipse.jdt.internal.core.util.Util.verbose("-> indexing " + zip.getName()); //$NON-NLS-1$
        long initialTime = System.currentTimeMillis();

        String[] paths = index.queryDocumentNames(""); // all file names //$NON-NLS-1$
        if (paths != null) {
          int max = paths.length;
          /* check integrity of the existing index file
           * if the length is equal to 0, we want to index the whole jar again
           * If not, then we want to check that there is no missing entry, if
           * one entry is missing then we recreate the index
           */
          String EXISTS = "OK"; //$NON-NLS-1$
          String DELETED = "DELETED"; //$NON-NLS-1$
          SimpleLookupTable indexedFileNames = new SimpleLookupTable(max == 0 ? 33 : max + 11);
          for (int i = 0; i < max; i++)
            indexedFileNames.put(paths[i], DELETED);
          for (Enumeration e = zip.entries(); e.hasMoreElements();) {
            // iterate each entry to index it
            ZipEntry ze = (ZipEntry) e.nextElement();
            String zipEntryName = ze.getName();
            if (Util.isClassFileName(zipEntryName))
              indexedFileNames.put(zipEntryName, EXISTS);
          }
          boolean needToReindex = indexedFileNames.elementSize != max; // a new file was added
          if (!needToReindex) {
            Object[] valueTable = indexedFileNames.valueTable;
            for (int i = 0, l = valueTable.length; i < l; i++) {
              if (valueTable[i] == DELETED) {
                needToReindex = true; // a file was deleted so re-index
                break;
              }
            }
            if (!needToReindex) {
              if (JobManager.VERBOSE)
                org.aspectj.org.eclipse.jdt.internal.core.util.Util.verbose("-> no indexing required (index is consistent with library) for " //$NON-NLS-1$
                + zip.getName() + " (" //$NON-NLS-1$
                + (System.currentTimeMillis() - initialTime) + "ms)"); //$NON-NLS-1$
              this.manager.saveIndex(index); // to ensure its placed into the saved state
              return true;
            }
          }
        }

        // Index the jar for the first time or reindex the jar in case the previous index file has been corrupted
        // index already existed: recreate it so that we forget about previous entries
        SearchParticipant participant = SearchEngine.getDefaultSearchParticipant();
        index = manager.recreateIndex(this.containerPath);
        if (index == null) {
          // failed to recreate index, see 73330
          manager.removeIndex(this.containerPath);
          return false;
        }

        for (Enumeration e = zip.entries(); e.hasMoreElements();) {
          if (this.isCancelled) {
            if (JobManager.VERBOSE)
              org.aspectj.org.eclipse.jdt.internal.core.util.Util.verbose("-> indexing of " + zip.getName() + " has been cancelled"); //$NON-NLS-1$ //$NON-NLS-2$
            return false;
          }

          // iterate each entry to index it
          ZipEntry ze = (ZipEntry) e.nextElement();
          if (Util.isClassFileName(ze.getName())) {
            final byte[] classFileBytes = org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip);
            JavaSearchDocument entryDocument = new JavaSearchDocument(ze, zipFilePath, classFileBytes, participant);
            this.manager.indexDocument(entryDocument, participant, index, this.containerPath);
          }
        }
        this.manager.saveIndex(index);
        if (JobManager.VERBOSE)
          org.aspectj.org.eclipse.jdt.internal.core.util.Util.verbose("-> done indexing of " //$NON-NLS-1$
            + zip.getName() + " (" //$NON-NLS-1$
            + (System.currentTimeMillis() - initialTime) + "ms)"); //$NON-NLS-1$
      } finally {
        if (zip != null) {
          if (JavaModelManager.ZIP_ACCESS_VERBOSE)
            System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Closing ZipFile " + zip); //$NON-NLS-1$  //$NON-NLS-2$
          zip.close();
        }
        monitor.exitWrite(); // free write lock
      }
    } catch (IOException e) {
      if (JobManager.VERBOSE) {
View Full Code Here

  for (int i = 0; i < length; i++) {
    PackageFragmentRoot root = (PackageFragmentRoot) roots[i];
    IPath path = root.getPath();
    try {
      if (root.isArchive()) {
        ZipFile zipFile = manager.getZipFile(path);
        cpLocations[index++] = new ClasspathJar(zipFile, ((ClasspathEntry) root.getRawClasspathEntry()).getAccessRuleSet());
      } else {
        Object target = JavaModel.getTarget(workspaceRoot, path, false);
        if (target == null) {
          // target doesn't exist any longer
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.