Class PathResource
- Direct Known Subclasses:
MountedPathResource
-
Field Summary
Modifier and TypeFieldDescriptionDeprecated, for removal: This API element is subject to removal in a future version.Using ResourceFactoryInternals.isSupported() instead. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Return true if this resource deeply contains the other Resource.boolean
boolean
exists()
Equivalent toFiles.exists(Path, LinkOption...)
with the following parameters:Resource.getPath()
andLinkOption.NOFOLLOW_LINKS
.The file name of the resource.getName()
The full name of the resource.getPath()
Return the Path corresponding to this resource.The real URI of the resource.getURI()
URI representing the resource.int
hashCode()
boolean
isAlias()
boolean
Return true if resource represents a directory of potential resources.boolean
True if the resource is readable.static boolean
isSameName
(Path pathA, Path pathB) Test if the paths are the same name.The time the resource was last modified.long
length()
Length of the resource.list()
List of contents of a directoryResource
.protected Resource
newResource
(Path path, URI uri) Internal override for creating a new PathResource.Resolve an existing Resource.toString()
protected URI
Ensure Path to URI is sane when it returns a directory reference.Methods inherited from class org.eclipse.jetty.util.resource.Resource
copyTo, dump, getAllResources, getPathTo, isContainedIn, isSameFile, iterator, newInputStream, newReadableByteChannel
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
SUPPORTED_SCHEMES
Deprecated, for removal: This API element is subject to removal in a future version.Using ResourceFactoryInternals.isSupported() instead.
-
-
Method Details
-
isSameName
Test if the paths are the same name.If the real path is not the same as the absolute path then we know that the real path is the alias for the provided path.
For OS's that are case insensitive, this should return the real (on-disk / case correct) version of the path.
We have to be careful on Windows and OSX.
Assume we have the following scenario:
Path a = new File("foo").toPath(); Files.createFile(a); Path b = new File("FOO").toPath();
There now exists a file called
foo
on disk. Using Windows or OSX, with a Path reference ofFOO
,Foo
,fOO
, etc.. means the following| OSX | Windows | Linux -----------------------+---------+------------+--------- Files.exists(a) | True | True | True Files.exists(b) | True | True | False Files.isSameFile(a,b) | True | True | False a.equals(b) | False | True | False
See the javadoc for Path.equals() for details about this FileSystem behavior difference
We also cannot rely on a.compareTo(b) as this is roughly equivalent in implementation to a.equals(b)
-
exists
public boolean exists()Description copied from class:Resource
Equivalent toFiles.exists(Path, LinkOption...)
with the following parameters:Resource.getPath()
andLinkOption.NOFOLLOW_LINKS
. -
getPath
Description copied from class:Resource
Return the Path corresponding to this resource. -
contains
Description copied from class:Resource
Return true if this resource deeply contains the other Resource. This resource must be a directory or a jar file or any form of resource capable of containing other resources. -
getRealPath
-
getRealURI
Description copied from class:Resource
The real URI of the resource.
If this Resource is an alias, (
Resource.isAlias()
), this URI will be different fromResource.getURI()
, and will point to the real name/location of the Resource.- Overrides:
getRealURI
in classResource
- Returns:
- The real URI location of this resource.
-
list
Description copied from class:Resource
List of contents of a directory
Resource
.Ordering is
FileSystem
dependent, so callers may wish to sort the return value to ensure deterministic behavior. -
isAlias
public boolean isAlias() -
getName
Description copied from class:Resource
The full name of the resource. -
getFileName
Description copied from class:Resource
The file name of the resource.
This is the last segment of the path.
- Specified by:
getFileName
in classResource
- Returns:
- the filename of the resource, or "" if there are no path segments (eg: path of "/"), or null if resource cannot determine a filename.
- See Also:
-
getURI
Description copied from class:Resource
URI representing the resource. -
resolve
Description copied from class:Resource
Resolve an existing Resource. -
newResource
Internal override for creating a new PathResource. Used by MountedPathResource (eg) -
isDirectory
public boolean isDirectory()Description copied from class:Resource
Return true if resource represents a directory of potential resources.- Specified by:
isDirectory
in classResource
- Returns:
- true if the represented resource is a container/directory.
-
isReadable
public boolean isReadable()Description copied from class:Resource
True if the resource is readable.- Specified by:
isReadable
in classResource
- Returns:
- true if the represented resource exists, and can read from.
-
lastModified
Description copied from class:Resource
The time the resource was last modified.- Overrides:
lastModified
in classResource
- Returns:
- the last modified time instant, or
Instant.EPOCH
if unable to obtain last modified.
-
length
public long length()Description copied from class:Resource
Length of the resource. -
toUri
Ensure Path to URI is sane when it returns a directory reference.This is different than
Path.toUri()
in that not all FileSystems seem to put the trailing slash on a directory reference in the URI.- Parameters:
path
- the path to convert to URI- Returns:
- the appropriate URI for the path
-
equals
-
hashCode
public int hashCode() -
toString
-