Class FileLocator

  • All Implemented Interfaces:
    Locator

    public final class FileLocator
    extends AbstractLocator

    A concrete Locator class that represents files.

    Instances of this class can be initialized with either a File object 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 Detail

      • getInstance

        public static FileLocator getInstance​(File file)
        Returns a FileLocator instance for the specified file.
        Parameters:
        file - the file (must not be null)
        Returns:
        the FileLocator instance for this file
        Throws:
        IllegalArgumentException - if the file is null
      • getInstance

        public static FileLocator getInstance​(String fileName)
        Returns a FileLocator instance for the specified file name.
        Parameters:
        fileName - the file name (must not be null)
        Returns:
        the FileLocator instance 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
      • 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.
        Overrides:
        equals in class Object
        Parameters:
        obj - the object to compare to
        Returns:
        a flag whether the objects are equal
      • hashCode

        public int hashCode()
        Returns a hash code for this object.
        Overrides:
        hashCode in class Object
        Returns:
        a hash code
      • toString

        public String toString()
        Returns a string representation for this object. This string will at least contain the path to the file as returned by getFileName().
        Overrides:
        toString in class Object
        Returns:
        a string for this object