Class PathResource
- Direct Known Subclasses:
MountedPathResource
-
Field Summary
FieldsModifier and TypeFieldDescriptionDeprecated, for removal: This API element is subject to removal in a future version.Using ResourceFactoryInternals.isSupported() instead. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturn true if this resource deeply contains the other Resource.booleanbooleanexists()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.inthashCode()booleanisAlias()booleanReturn true if resource represents a directory of potential resources.booleanTrue if the resource is readable.static booleanisSameName(Path pathA, Path pathB) Test if the paths are the same name.The time the resource was last modified.longlength()Length of the resource.list()List of contents of a directoryResource.protected ResourcenewResource(Path path, URI uri) Internal override for creating a new PathResource.Resolve an existing Resource.toString()protected URIEnsure Path to URI is sane when it returns a directory reference.Methods inherited from class Resource
copyTo, dump, getAllResources, getPathTo, isContainedIn, isSameFile, iterator, newInputStream, newReadableByteChannelMethods inherited from interface 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
fooon 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 | FalseSee 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:ResourceEquivalent toFiles.exists(Path, LinkOption...)with the following parameters:Resource.getPath()andLinkOption.NOFOLLOW_LINKS. -
getPath
-
contains
Description copied from class:ResourceReturn 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:ResourceThe 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:
getRealURIin classResource- Returns:
- The real URI location of this resource.
-
list
Description copied from class:ResourceList of contents of a directory
Resource.Ordering is
FileSystemdependent, so callers may wish to sort the return value to ensure deterministic behavior. -
isAlias
-
getName
-
getFileName
Description copied from class:ResourceThe file name of the resource.
This is the last segment of the path.
- Specified by:
getFileNamein 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
-
resolve
Description copied from class:ResourceResolve an existing Resource. -
newResource
-
isDirectory
public boolean isDirectory()Description copied from class:ResourceReturn true if resource represents a directory of potential resources.- Specified by:
isDirectoryin classResource- Returns:
- true if the represented resource is a container/directory.
-
isReadable
public boolean isReadable()Description copied from class:ResourceTrue if the resource is readable.- Specified by:
isReadablein classResource- Returns:
- true if the represented resource exists, and can read from.
-
lastModified
Description copied from class:ResourceThe time the resource was last modified.- Overrides:
lastModifiedin classResource- Returns:
- the last modified time instant, or
Instant.EPOCHif unable to obtain last modified.
-
length
-
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
-
toString
-