1 19 20 21 package org.netbeans.modules.javacore.scanning; 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.Enumeration ; 25 import java.util.HashMap ; 26 import java.util.Map ; 27 import java.util.zip.ZipEntry ; 28 import java.util.zip.ZipFile ; 29 33 class ZipArchiveInfo { 34 ZipFile zipFile; 35 String offset; 36 Map directoryMap=new HashMap (1000); 37 ZipDirInfo rootInfo; 38 39 40 ZipArchiveInfo(File f, String offset) throws IOException { 41 zipFile=new ZipFile (f); 42 this.offset = offset; 43 rootInfo=new ZipDirInfo("",""); } 45 46 void close() throws IOException { 47 if (zipFile != null) zipFile.close(); 48 } 49 50 FileInfo getRootFileInfo() { 51 Enumeration en=zipFile.entries(); 52 53 while(en.hasMoreElements()) { 54 ZipEntry entry=(ZipEntry )en.nextElement(); 55 if (!entry.isDirectory()) { 56 String name=entry.getName(); 57 if (offset != null) { 58 if (name.startsWith(offset)) { 59 name = name.substring(offset.length()); 60 } 61 else { 62 continue; 63 } 64 } 65 int lastSlashIndex = name.lastIndexOf('/'); 66 String directoryName=""; 67 String shortName=name; 68 69 if (lastSlashIndex > -1) { 70 directoryName=name.substring(0, lastSlashIndex); 71 shortName=name.substring(lastSlashIndex+1); 72 } 73 getDirectory(directoryName).addEntry(zipFile,entry,shortName,name); 74 } 75 } 76 return rootInfo; 77 } 78 79 private ZipDirInfo getDirectory(String dirName) { 80 ZipDirInfo zipDir=(ZipDirInfo)directoryMap.get(dirName); 81 82 if (zipDir==null){ 83 ZipDirInfo parentInfo; 84 int lastSlashIndex = dirName.lastIndexOf('/'); 85 String shortName=dirName; 86 if (lastSlashIndex > -1) { 87 String parentDirName = dirName.substring(0, lastSlashIndex); 88 shortName=dirName.substring(lastSlashIndex+1); 89 parentInfo=getDirectory(parentDirName); 90 } else { 91 parentInfo=rootInfo; 92 } 93 zipDir=new ZipDirInfo(dirName,shortName); 94 parentInfo.addDir(zipDir); 95 directoryMap.put(dirName,zipDir); 96 } 97 return zipDir; 98 } 99 } 100 | Popular Tags |