Package java.util.zip

Examples of java.util.zip.ZipFile$MyEnumeration


  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

    private static ZipInfoProperties checkFile(String filename)
    {
        // try to create a ZipFile from it
        try
        {
            ZipFile zf = new ZipFile(filename);
            // try to get a ZipEntry from the ZipFile

            ZipEntry thisEntry = null;

            for (int i =0; i < infoNames.length; i++)
            {
                thisEntry = zf.getEntry(infoNames[i]);
                if (thisEntry != null)
                {
                    break;
                }
            }

            if (thisEntry == null)
            {
                return null;
            }

            InputStream bis = zf.getInputStream(thisEntry);
            if (bis == null)
            {
                return null;
            }
View Full Code Here

          if (transletTimestamp < xslTimestamp)
              return null;
      }
     
        // Create a ZipFile object for the jar file
        ZipFile jarFile = null;
        try {
            jarFile = new ZipFile(file);
        }
        catch (IOException e) {
            return null;
        }
     
        String transletPath = fullClassName.replace('.', '/');
        String transletAuxPrefix = transletPath + "$";
        String transletFullName = transletPath + ".class";
     
        Vector bytecodes = new Vector();     
     
        // Iterate through all entries in the jar file to find the
        // translet and auxiliary classes.
        Enumeration entries = jarFile.entries();
        while (entries.hasMoreElements())
        {
            ZipEntry entry = (ZipEntry)entries.nextElement();
            String entryName = entry.getName();
            if (entry.getSize() > 0 &&
                (entryName.equals(transletFullName) ||
                  (entryName.endsWith(".class") &&
                      entryName.startsWith(transletAuxPrefix))))
            {
              try {
                    InputStream input = jarFile.getInputStream(entry);
                    int size = (int)entry.getSize();
                    byte[] bytes = new byte[size];
                    readFromInputStream(bytes, input, size);
                    input.close();
                    bytecodes.addElement(bytes);
View Full Code Here

TOP

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

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.