Class FileLocator
- java.lang.Object
-
- org.apache.commons.configuration2.io.FileLocator
-
public final class FileLocator extends java.lang.Object
A class describing the location of a file.
An instance of this class provides information for locating and accessing a file. The file location can be defined
- as a URL; this identifies a file in a unique way
- as a combination of base path and file name; if this variant is used, there may be an additional location step required in order to identify the referenced file (for instance, the file name may be interpreted as the name of a resource to be loaded from class path).
In addition, other properties are available which are also needed for loading or saving a file, like the underlying
FileSystem
. The encoding to be used when accessing the represented data is also part of the data contained in an instance; if no encoding is set explicitly, the platform's default encoding is used.Instances of this class are immutable and thus can be safely shared between arbitrary components.
FileHandler
also uses an instance to reference the associated file. Instances are created using a builder.FileLocatorUtils
offers convenience methods for obtaining such a builder.- Since:
- 2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileLocator.FileLocatorBuilder
A typical builder implementation for creatingFileLocator
objects.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
basePath
The base path.private java.lang.String
encoding
The encoding.private java.lang.String
fileName
The file name.private FileSystem
fileSystem
The file system.private FileLocationStrategy
locationStrategy
The file location strategy.private java.net.URL
sourceURL
The source URL.private URLConnectionOptions
urlConnectionOptions
The source URL connection options.
-
Constructor Summary
Constructors Constructor Description FileLocator(FileLocator.FileLocatorBuilder builder)
Creates a new instance ofFileLocatorImpl
and initializes it from the given builder instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
Compares this object with another one.java.lang.String
getBasePath()
Gets the base path stored in this locator or null if it is undefined.java.lang.String
getEncoding()
Gets the encoding stored in this locator or null if it is undefined.java.lang.String
getFileName()
Gets the file name stored in this locator or null if it is undefined.FileSystem
getFileSystem()
Gets theFileSystem
to be used for accessing the file referenced by this locator or null if it is undefined.FileLocationStrategy
getLocationStrategy()
Gets theFileLocationStrategy
to be used for locating the referenced file.java.net.URL
getSourceURL()
Gets the URL pointing to the referenced source file or null if it is undefined.URLConnectionOptions
getURLConnectionOptions()
Gets the URLConnectionOptionsint
hashCode()
Returns a hash code for this object.java.lang.String
toString()
-
-
-
Field Detail
-
basePath
private final java.lang.String basePath
The base path.
-
encoding
private final java.lang.String encoding
The encoding.
-
fileName
private final java.lang.String fileName
The file name.
-
fileSystem
private final FileSystem fileSystem
The file system.
-
locationStrategy
private final FileLocationStrategy locationStrategy
The file location strategy.
-
sourceURL
private final java.net.URL sourceURL
The source URL.
-
urlConnectionOptions
private final URLConnectionOptions urlConnectionOptions
The source URL connection options.
-
-
Constructor Detail
-
FileLocator
public FileLocator(FileLocator.FileLocatorBuilder builder)
Creates a new instance ofFileLocatorImpl
and initializes it from the given builder instance- Parameters:
builder
- the builder
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object obj)
Compares this object with another one. Two instances ofFileLocatorImpl
are considered equal if all of their properties are equal.- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- the object to compare to- Returns:
- a flag whether these objects are equal
-
getBasePath
public java.lang.String getBasePath()
Gets the base path stored in this locator or null if it is undefined.- Returns:
- the base path
-
getEncoding
public java.lang.String getEncoding()
Gets the encoding stored in this locator or null if it is undefined.- Returns:
- the encoding
-
getFileName
public java.lang.String getFileName()
Gets the file name stored in this locator or null if it is undefined.- Returns:
- the file name
-
getFileSystem
public FileSystem getFileSystem()
Gets theFileSystem
to be used for accessing the file referenced by this locator or null if it is undefined.- Returns:
- the
FileSystem
-
getLocationStrategy
public FileLocationStrategy getLocationStrategy()
Gets theFileLocationStrategy
to be used for locating the referenced file. If no specificFileLocationStrategy
has been set, result is null. This means that the default strategy should be used.- Returns:
- the
FileLocationStrategy
to be used
-
getSourceURL
public java.net.URL getSourceURL()
Gets the URL pointing to the referenced source file or null if it is undefined.- Returns:
- the source URL
-
getURLConnectionOptions
public URLConnectionOptions getURLConnectionOptions()
Gets the URLConnectionOptions- Returns:
- the URLConnectionOptions
-
hashCode
public int hashCode()
Returns a hash code for this object.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- a hash code for this object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-