Package net.sf.jguiraffe.locators
Class FileLocator
- java.lang.Object
-
- net.sf.jguiraffe.locators.AbstractLocator
-
- net.sf.jguiraffe.locators.FileLocator
-
- All Implemented Interfaces:
Locator
public final class FileLocator extends AbstractLocator
A concrete
Locatorclass that represents files.Instances of this class can be initialized with either a
Fileobject or with the name of a file. Based on this data the locator methods are implemented in an appropriate way.Note that this class does not check whether the passed in file exists. So if an input stream is to be obtained for this file, it is possible that a file not found exception gets thrown.
Instances of this class are created using the
getInstance()factory methods. They are immutable and thus can be shared between multiple threads.- Version:
- $Id: FileLocator.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)Compares this object with another one.FilegetFile()Returns the represented file resource.StringgetFileName()Returns the name of the represented file.static FileLocatorgetInstance(File file)Returns aFileLocatorinstance for the specified file.static FileLocatorgetInstance(String fileName)Returns aFileLocatorinstance for the specified file name.URLgetURL()Returns the URL for the represented file.inthashCode()Returns a hash code for this object.StringtoString()Returns a string representation for this object.-
Methods inherited from class net.sf.jguiraffe.locators.AbstractLocator
getInputStream
-
-
-
-
Method Detail
-
getInstance
public static FileLocator getInstance(File file)
Returns aFileLocatorinstance for the specified file.- Parameters:
file- the file (must not be null)- Returns:
- the
FileLocatorinstance for this file - Throws:
IllegalArgumentException- if the file is null
-
getInstance
public static FileLocator getInstance(String fileName)
Returns aFileLocatorinstance for the specified file name.- Parameters:
fileName- the file name (must not be null)- Returns:
- the
FileLocatorinstance for this file - Throws:
IllegalArgumentException- if the file name is null
-
getURL
public URL getURL()
Returns the URL for the represented file.- Returns:
- the URL
- Throws:
LocatorException- if an error occurs
-
getFile
public File getFile()
Returns the represented file resource.- Specified by:
getFilein interfaceLocator- Overrides:
getFilein classAbstractLocator- Returns:
- the file
-
getFileName
public String getFileName()
Returns the name of the represented file. This is an absolute file path.- Returns:
- the file name
-
equals
public boolean equals(Object obj)
Compares this object with another one. Two instances of this class are considered equal if and only if they point to the same file.
-
hashCode
public int hashCode()
Returns a hash code for this object.
-
-