KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > classfile > impl > ZipFileCodeBaseEntry


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2006, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs.classfile.impl;
21
22 import java.io.IOException JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.util.zip.ZipEntry JavaDoc;
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 /**
33  * Implementation of ICodeBaseEntry for resources in zipfile codebases.
34  *
35  * @author David Hovemeyer
36  */

37 public class ZipFileCodeBaseEntry extends AbstractScannableCodeBaseEntry implements ICodeBaseEntry {
38     private final ZipFileCodeBase codeBase;
39     private final ZipEntry JavaDoc zipEntry;
40     
41     public ZipFileCodeBaseEntry(ZipFileCodeBase codeBase, ZipEntry JavaDoc zipEntry) {
42         this.codeBase = codeBase;
43         this.zipEntry = zipEntry;
44     }
45     
46     /* (non-Javadoc)
47      * @see edu.umd.cs.findbugs.classfile.ICodeBaseEntry#getNumBytes()
48      */

49     public int getNumBytes() {
50         return (int) zipEntry.getSize();
51     }
52     
53     /* (non-Javadoc)
54      * @see edu.umd.cs.findbugs.classfile.ICodeBaseEntry#openResource()
55      */

56     public InputStream JavaDoc openResource() throws IOException JavaDoc {
57         return codeBase.zipFile.getInputStream(zipEntry);
58     }
59
60     /* (non-Javadoc)
61      * @see edu.umd.cs.findbugs.classfile.impl.AbstractScannableCodeBaseEntry#getCodeBase()
62      */

63     @Override JavaDoc
64     public AbstractScannableCodeBase getCodeBase() {
65         return codeBase;
66     }
67     
68     /* (non-Javadoc)
69      * @see edu.umd.cs.findbugs.classfile.impl.AbstractScannableCodeBaseEntry#getRealResourceName()
70      */

71     @Override JavaDoc
72     public String JavaDoc getRealResourceName() {
73         return zipEntry.getName();
74     }
75     
76     /* (non-Javadoc)
77      * @see edu.umd.cs.findbugs.classfile.ICodeBaseEntry#getClassDescriptor()
78      */

79     public ClassDescriptor getClassDescriptor() {
80         return ClassDescriptor.fromResourceName(getResourceName());
81     }
82     
83     /* (non-Javadoc)
84      * @see java.lang.Object#equals(java.lang.Object)
85      */

86     @Override JavaDoc
87     public boolean equals(Object JavaDoc 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     /* (non-Javadoc)
97      * @see java.lang.Object#hashCode()
98      */

99     @Override JavaDoc
100     public int hashCode() {
101         return 7919 * codeBase.hashCode() + zipEntry.hashCode();
102     }
103     
104     /* (non-Javadoc)
105      * @see java.lang.Object#toString()
106      */

107     @Override JavaDoc
108     public String JavaDoc toString() {
109         return getCodeBase() + ":" + getResourceName();
110     }
111 }
112
Popular Tags