KickJava   Java API By Example, From Geeks To Geeks.

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


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.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25
26 import edu.umd.cs.findbugs.classfile.ClassDescriptor;
27 import edu.umd.cs.findbugs.classfile.ICodeBase;
28 import edu.umd.cs.findbugs.classfile.ICodeBaseEntry;
29 import edu.umd.cs.findbugs.classfile.InvalidClassFileFormatException;
30
31 /**
32  * Codebase entry class for directory codebases.
33  *
34  * @author David Hovemeyer
35  */

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

48     public int getNumBytes() {
49         File JavaDoc fullPath = codeBase.getFullPathOfResource(realResourceName);
50         if (!fullPath.exists()) {
51             return -1;
52         }
53         return (int) fullPath.length();
54     }
55
56     /* (non-Javadoc)
57      * @see edu.umd.cs.findbugs.classfile.ICodeBaseEntry#openResource()
58      */

59     public InputStream JavaDoc openResource() throws IOException JavaDoc {
60         return codeBase.openFile(realResourceName);
61     }
62
63     /* (non-Javadoc)
64      * @see edu.umd.cs.findbugs.classfile.impl.AbstractScannableCodeBaseEntry#getCodeBase()
65      */

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

74     @Override JavaDoc
75     public String JavaDoc getRealResourceName() {
76         return realResourceName;
77     }
78     
79     /* (non-Javadoc)
80      * @see edu.umd.cs.findbugs.classfile.ICodeBaseEntry#getClassDescriptor()
81      */

82     public ClassDescriptor getClassDescriptor() throws InvalidClassFileFormatException {
83         return ClassDescriptor.fromResourceName(getResourceName());
84     }
85     
86     /* (non-Javadoc)
87      * @see java.lang.Object#equals(java.lang.Object)
88      */

89     @Override JavaDoc
90     public boolean equals(Object JavaDoc obj) {
91         if (obj == null || obj.getClass() != this.getClass()) {
92             return false;
93         }
94         DirectoryCodeBaseEntry other = (DirectoryCodeBaseEntry) obj;
95         return this.codeBase.equals(other.codeBase)
96             && this.realResourceName.equals(other.realResourceName);
97     }
98     
99     /* (non-Javadoc)
100      * @see java.lang.Object#hashCode()
101      */

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

110     @Override JavaDoc
111     public String JavaDoc toString() {
112         return getCodeBase() + ":" + getResourceName();
113     }
114 }
115
Popular Tags