Package java.util.zip

Examples of java.util.zip.ZipFile$Window


      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

  protected boolean computeChildren(OpenableElementInfo info, Map newElements) throws JavaModelException {
   
    ArrayList vChildren= new ArrayList();
    final int JAVA = 0;
    final int NON_JAVA = 1;
    ZipFile jar= null;
    try {
      jar= getJar();
 
      HashtableOfArrayToObject packageFragToTypes= new HashtableOfArrayToObject();
 
      // always create the default package
      packageFragToTypes.put(CharOperation.NO_STRINGS, new ArrayList[] { EMPTY_LIST, EMPTY_LIST });
 
      for (Enumeration e= jar.entries(); e.hasMoreElements();) {
        ZipEntry member= (ZipEntry) e.nextElement();
        initPackageFragToTypes(packageFragToTypes, member.getName(), member.isDirectory());
      }
     
      //loop through all of referenced packages, creating package fragments if necessary
      // and cache the entry names in the infos created for those package fragments
      for (int i = 0, length = packageFragToTypes.keyTable.length; i < length; i++) {
        String[] pkgName = (String[]) packageFragToTypes.keyTable[i];
        if (pkgName == null) continue;
       
        ArrayList[] entries= (ArrayList[]) packageFragToTypes.get(pkgName);
        JarPackageFragment packFrag= (JarPackageFragment) getPackageFragment(pkgName);
        JarPackageFragmentInfo fragInfo= new JarPackageFragmentInfo();
        int resLength= entries[NON_JAVA].size();
        if (resLength == 0) {
          packFrag.computeNonJavaResources(CharOperation.NO_STRINGS, packFrag, fragInfo, jar.getName());
        } else {
          String[] resNames= new String[resLength];
          entries[NON_JAVA].toArray(resNames);
          packFrag.computeNonJavaResources(resNames, packFrag, fragInfo, jar.getName());
        }
        packFrag.computeChildren(fragInfo, entries[JAVA]);
        newElements.put(packFrag, fragInfo);
        vChildren.add(packFrag);
      }
View Full Code Here

public byte[] getBytes() throws JavaModelException {
  JavaElement pkg = (JavaElement) getParent();
  if (pkg instanceof JarPackageFragment) {
    JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent();
    ZipFile zip = null;
    try {
      zip = root.getJar();
      String entryName = Util.concatWith(((PackageFragment) pkg).names, getElementName(), '/');
      ZipEntry ze = zip.getEntry(entryName);
      if (ze != null) {
        return org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip);
      }
      throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this));
    } catch (IOException ioe) {
View Full Code Here

    return Util.getResourceContentsAsByteArray(file);
  }
}
private IBinaryType getJarBinaryTypeInfo(PackageFragment pkg) throws CoreException, IOException, ClassFormatException {
  JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent();
  ZipFile zip = null;
  try {
    zip = root.getJar();
    String entryName = Util.concatWith(pkg.names, getElementName(), '/');
    ZipEntry ze = zip.getEntry(entryName);
    if (ze != null) {
      byte contents[] = org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip);
      String fileName = root.getHandleIdentifier() + IDependent.JAR_FILE_ENTRY_SEPARATOR + entryName;
      return new ClassFileReader(contents, fileName.toCharArray(), true/*fully initialize so as to not keep a reference to the byte array*/);
    }
 
View Full Code Here

  IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();
  try {
    if (!root.isArchive())
      return Util.newClassFileReader(type.getResource());

    ZipFile zipFile = null;
    try {
      IPath zipPath = root.getPath();
      if (JavaModelManager.ZIP_ACCESS_VERBOSE)
        System.out.println("(" + Thread.currentThread() + ") [MatchLocator.classFileReader()] Creating ZipFile on " + zipPath); //$NON-NLS-1$  //$NON-NLS-2$
      zipFile = manager.getZipFile(zipPath);
View Full Code Here

    PackageFragmentRoot root = (PackageFragmentRoot) pkg.getParent();
    if (root.isArchive()) {
      // class file in a jar
      String classFileName = classFile.getElementName();
      String classFilePath = Util.concatWith(pkg.names, classFileName, '/');
      ZipFile zipFile = null;
      try {
        zipFile = ((JarPackageFragmentRoot) root).getJar();
        info = ClassFileReader.read(zipFile, classFilePath);
      } finally {
        JavaModelManager.getJavaModelManager().closeZipFile(zipFile);
View Full Code Here

      JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) root;
      IJavaProject project = jarPackageFragmentRoot.getJavaProject();
      String sourceLevel = null;
      String complianceLevel = null;
      JavaModelManager manager = JavaModelManager.getJavaModelManager();
      ZipFile zip = null;
      try {
        zip = manager.getZipFile(jarPackageFragmentRoot.getPath());
        for (Enumeration entries = zip.entries(); entries.hasMoreElements(); ) {
          ZipEntry entry = (ZipEntry) entries.nextElement();
          String entryName = entry.getName();
          if (!entry.isDirectory()) {
            int index = entryName.indexOf('/');
            if (index != -1 && Util.isClassFileName(entryName)) {
              String firstLevelPackageName = entryName.substring(0, index);
              if (!firstLevelPackageNames.contains(firstLevelPackageName)) {
                if (sourceLevel == null) {
                  sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
                  complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
                }
                IStatus status = JavaConventions.validatePackageName(firstLevelPackageName, sourceLevel, complianceLevel);
                if (status.isOK() || status.getSeverity() == IStatus.WARNING) {
                  firstLevelPackageNames.add(firstLevelPackageName);
                }
              }
            } else if (Util.isClassFileName(entryName)) {
              containsADefaultPackage = true;
            }           
          }
        }
      } catch (CoreException e) {
        // ignore
      } finally {
        manager.closeZipFile(zip); // handle null case
      }
    } else {
      Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), root.getPath(), true);
      if (target instanceof IResource) {
        IResource resource = (IResource) target;
        if (resource instanceof IContainer) {
          try {
            IResource[] members = ((IContainer) resource).members();
            for (int i = 0, max = members.length; i < max; i++) {
              IResource member = members[i];
              if (member.getType() == IResource.FOLDER) {
                firstLevelPackageNames.add(member.getName());
              } else if (Util.isClassFileName(member.getName())) {
                containsADefaultPackage = true;
              }
            }
          } catch (CoreException e) {
            // ignore
          }
        }
      } else if (target instanceof File) {
        File file = (File)target;
        if (file.isDirectory()) {
          File[] files = file.listFiles();
          for (int i = 0, max = files.length; i < max; i++) {
            File currentFile = files[i];
            if (currentFile.isDirectory()) {
              firstLevelPackageNames.add(currentFile.getName());
            } else if (Util.isClassFileName(currentFile.getName())) {
              containsADefaultPackage = true;
            }
          }
        }
      }
    }

    if (Util.isArchiveFileName(this.sourcePath.lastSegment())) {
      JavaModelManager manager = JavaModelManager.getJavaModelManager();
      ZipFile zip = null;
      try {
        zip = manager.getZipFile(this.sourcePath);
        for (Enumeration entries = zip.entries(); entries.hasMoreElements(); ) {
          ZipEntry entry = (ZipEntry) entries.nextElement();
          String entryName;
          if (!entry.isDirectory() && org.aspectj.org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(entryName = entry.getName())) {
            IPath path = new Path(entryName);
            int segmentCount = path.segmentCount();
View Full Code Here

  public char[] findSource(String fullName) {
    char[] source = null;
    if (Util.isArchiveFileName(this.sourcePath.lastSegment())) {
      // try to get the entry
      ZipEntry entry = null;
      ZipFile zip = null;
      JavaModelManager manager = JavaModelManager.getJavaModelManager();
      try {
        zip = manager.getZipFile(this.sourcePath);
        entry = zip.getEntry(fullName);
        if (entry != null) {
          // now read the source code
          source = readSource(entry, zip);
        }
      } catch (CoreException e) {
View Full Code Here

        IFile classFile = findFirstClassFile((IFolder) targetLibrary); // only internal classfolders are allowed
        if (classFile != null)
          reader = Util.newClassFileReader(classFile);
      } else {
        // root is a jar file or a zip file
        ZipFile jar = null;
        try {
          IPath path = null;
          if (targetLibrary instanceof IResource) {
            path = ((IResource)targetLibrary).getFullPath();
          } else if (targetLibrary instanceof File){
            File f = (File) targetLibrary;
            if (!f.isDirectory()) {
              path = new Path(((File)targetLibrary).getPath());
            }
          }
          if (path != null) {
            jar = JavaModelManager.getJavaModelManager().getZipFile(path);
            for (Enumeration e= jar.entries(); e.hasMoreElements();) {
              ZipEntry member= (ZipEntry) e.nextElement();
              String entryName= member.getName();
              if (org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entryName)) {
                reader = ClassFileReader.read(jar, entryName);
                break;
View Full Code Here

TOP

Related Classes of java.util.zip.ZipFile$Window

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.