1 19 20 package edu.umd.cs.findbugs.classfile.impl; 21 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.util.zip.ZipEntry ; 25 26 import edu.umd.cs.findbugs.classfile.CheckedAnalysisException; 27 import edu.umd.cs.findbugs.classfile.ClassDescriptor; 28 import edu.umd.cs.findbugs.classfile.ICodeBase; 29 import edu.umd.cs.findbugs.classfile.ICodeBaseEntry; 30 import edu.umd.cs.findbugs.classfile.ResourceNotFoundException; 31 32 37 public class ZipFileCodeBaseEntry extends AbstractScannableCodeBaseEntry implements ICodeBaseEntry { 38 private final ZipFileCodeBase codeBase; 39 private final ZipEntry zipEntry; 40 41 public ZipFileCodeBaseEntry(ZipFileCodeBase codeBase, ZipEntry zipEntry) { 42 this.codeBase = codeBase; 43 this.zipEntry = zipEntry; 44 } 45 46 49 public int getNumBytes() { 50 return (int) zipEntry.getSize(); 51 } 52 53 56 public InputStream openResource() throws IOException { 57 return codeBase.zipFile.getInputStream(zipEntry); 58 } 59 60 63 @Override 64 public AbstractScannableCodeBase getCodeBase() { 65 return codeBase; 66 } 67 68 71 @Override 72 public String getRealResourceName() { 73 return zipEntry.getName(); 74 } 75 76 79 public ClassDescriptor getClassDescriptor() { 80 return ClassDescriptor.fromResourceName(getResourceName()); 81 } 82 83 86 @Override 87 public boolean equals(Object obj) { 88 if (obj == null || obj.getClass() != this.getClass()) { 89 return false; 90 } 91 ZipFileCodeBaseEntry other = (ZipFileCodeBaseEntry) obj; 92 return this.codeBase.equals(other.codeBase) 93 && this.zipEntry.equals(other.zipEntry); 94 } 95 96 99 @Override 100 public int hashCode() { 101 return 7919 * codeBase.hashCode() + zipEntry.hashCode(); 102 } 103 104 107 @Override 108 public String toString() { 109 return getCodeBase() + ":" + getResourceName(); 110 } 111 } 112 | Popular Tags |