Class SingleFileCodeBase
- java.lang.Object
-
- edu.umd.cs.findbugs.classfile.impl.SingleFileCodeBase
-
- All Implemented Interfaces:
ICodeBase
,IScannableCodeBase
,java.lang.AutoCloseable
public class SingleFileCodeBase extends java.lang.Object implements IScannableCodeBase
Implementation of ICodeBase for a single classfile.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface edu.umd.cs.findbugs.classfile.ICodeBase
ICodeBase.Discovered
-
-
Field Summary
Fields Modifier and Type Field Description private ICodeBaseLocator
codeBaseLocator
private java.lang.String
fileName
private ICodeBase.Discovered
howDiscovered
private boolean
isAppCodeBase
private long
lastModifiedTime
private java.lang.String
resourceName
private boolean
resourceNameKnown
-
Constructor Summary
Constructors Constructor Description SingleFileCodeBase(ICodeBaseLocator codeBaseLocator, java.lang.String fileName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
This method should be called when done using the code base.boolean
containsSourceFiles()
Return whether or not this code base contains any source files.(package private) ClassDescriptor
getClassDescriptor()
ICodeBaseLocator
getCodeBaseLocator()
Get the codebase locator describing the location of this codebase.ICodeBase.Discovered
getHowDiscovered()
Return how this codebase was discovered.long
getLastModifiedTime()
Get timestamp indicating the most recent time when any of the files in the codebase were modified.(package private) int
getNumBytes()
Return the number of bytes in the file.java.lang.String
getPathName()
Get the filesystem pathname of this codebase.(package private) java.lang.String
getResourceName()
Get the resource name of the single file.boolean
isApplicationCodeBase()
Return whether or not this codebase is an application codebase.ICodeBaseIterator
iterator()
Get an iterator over the resources in the this code base.ICodeBaseEntry
lookupResource(java.lang.String resourceName)
Look up a resource in this code base.(package private) java.io.InputStream
openFile()
void
setApplicationCodeBase(boolean isAppCodeBase)
Designate this code base as an application codebase.void
setHowDiscovered(ICodeBase.Discovered howDiscovered)
Set how this codebase was discovered.void
setLastModifiedTime(long lastModifiedTime)
Set timestamp indicating the most recent time when any of the files in the codebase were modified.java.lang.String
toString()
-
-
-
Field Detail
-
codeBaseLocator
private final ICodeBaseLocator codeBaseLocator
-
fileName
private final java.lang.String fileName
-
isAppCodeBase
private boolean isAppCodeBase
-
howDiscovered
private ICodeBase.Discovered howDiscovered
-
lastModifiedTime
private long lastModifiedTime
-
resourceNameKnown
private boolean resourceNameKnown
-
resourceName
private java.lang.String resourceName
-
-
Constructor Detail
-
SingleFileCodeBase
public SingleFileCodeBase(ICodeBaseLocator codeBaseLocator, java.lang.String fileName)
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getCodeBaseLocator
public ICodeBaseLocator getCodeBaseLocator()
Description copied from interface:ICodeBase
Get the codebase locator describing the location of this codebase.- Specified by:
getCodeBaseLocator
in interfaceICodeBase
- Returns:
- the ICodeBaseLocator
-
containsSourceFiles
public boolean containsSourceFiles() throws java.lang.InterruptedException
Description copied from interface:ICodeBase
Return whether or not this code base contains any source files.- Specified by:
containsSourceFiles
in interfaceICodeBase
- Returns:
- true if the code base contains source file(s), false if it does not contain source files
- Throws:
java.lang.InterruptedException
-
iterator
public ICodeBaseIterator iterator() throws java.lang.InterruptedException
Description copied from interface:IScannableCodeBase
Get an iterator over the resources in the this code base.- Specified by:
iterator
in interfaceIScannableCodeBase
- Returns:
- ICodeBaseIterator over the resources in the code base
- Throws:
java.lang.InterruptedException
-
lookupResource
public ICodeBaseEntry lookupResource(java.lang.String resourceName)
Description copied from interface:ICodeBase
Look up a resource in this code base.- Specified by:
lookupResource
in interfaceICodeBase
- Parameters:
resourceName
- name of the resource to look up- Returns:
- ICodeBaseEntry representing the resource or null if the resource cannot be found in this code base
-
setApplicationCodeBase
public void setApplicationCodeBase(boolean isAppCodeBase)
Description copied from interface:ICodeBase
Designate this code base as an application codebase.- Specified by:
setApplicationCodeBase
in interfaceICodeBase
- Parameters:
isAppCodeBase
- true if this is an application codebase, false if not
-
isApplicationCodeBase
public boolean isApplicationCodeBase()
Description copied from interface:ICodeBase
Return whether or not this codebase is an application codebase.- Specified by:
isApplicationCodeBase
in interfaceICodeBase
- Returns:
- true if this is an application codebase, false if not
-
setHowDiscovered
public void setHowDiscovered(ICodeBase.Discovered howDiscovered)
Description copied from interface:ICodeBase
Set how this codebase was discovered.- Specified by:
setHowDiscovered
in interfaceICodeBase
- Parameters:
howDiscovered
- one of the constants SPECIFIED, NESTED, IN_JAR_MANIFEST, or IN_SYSTEM_CLASSPATH
-
getHowDiscovered
public ICodeBase.Discovered getHowDiscovered()
Description copied from interface:ICodeBase
Return how this codebase was discovered.- Specified by:
getHowDiscovered
in interfaceICodeBase
- Returns:
- one of the constants SPECIFIED, NESTED, IN_JAR_MANIFEST, or IN_SYSTEM_CLASSPATH
-
setLastModifiedTime
public void setLastModifiedTime(long lastModifiedTime)
Description copied from interface:ICodeBase
Set timestamp indicating the most recent time when any of the files in the codebase were modified.- Specified by:
setLastModifiedTime
in interfaceICodeBase
- Parameters:
lastModifiedTime
- timestamp when any codebase files were most-recently modified
-
getLastModifiedTime
public long getLastModifiedTime()
Description copied from interface:ICodeBase
Get timestamp indicating the most recent time when any of the files in the codebase were modified. This information is only likely to be accurate if an ICodeBaseIterator has been used to scan the resources in the codebase (scannable codebases only, obviously).- Specified by:
getLastModifiedTime
in interfaceICodeBase
- Returns:
- timestamp when any codebase files were most-recently modified, -1 if unknown
-
getPathName
public java.lang.String getPathName()
Description copied from interface:ICodeBase
Get the filesystem pathname of this codebase.- Specified by:
getPathName
in interfaceICodeBase
- Returns:
- the filesystem pathname of this codebase, or null if this codebase is not accessible via the filesystem
-
openFile
java.io.InputStream openFile() throws java.io.IOException
- Throws:
java.io.IOException
-
close
public void close()
Description copied from interface:ICodeBase
This method should be called when done using the code base.
-
getResourceName
java.lang.String getResourceName()
Get the resource name of the single file. We have to open the file and parse the constant pool in order to find this out.- Returns:
- the resource name (e.g., "java/lang/String.class" if the class is java.lang.String)
-
getClassDescriptor
ClassDescriptor getClassDescriptor() throws ResourceNotFoundException, InvalidClassFileFormatException
-
getNumBytes
int getNumBytes()
Return the number of bytes in the file.- Returns:
- the number of bytes in the file, or -1 if the file's length can't be determined
-
-