- Direct Known Subclasses:
MountedPathResource
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidCopy the Resource to the new destination file.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 this resource is contained in the Resource r, either because r is a folder or a jar file or any form of resource capable of containing other resources.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 org.eclipse.jetty.util.resource.Resource
dump, getAllResources, iterator, newInputStream, newReadableByteChannelMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
SUPPORTED_SCHEMES
-
-
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
Description copied from class:ResourceReturn the Path corresponding to this resource. -
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
public boolean isAlias() -
getName
Description copied from class:ResourceThe full name of the resource. -
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 has no path.
- See Also:
-
getURI
Description copied from class:ResourceURI representing the resource. -
resolve
Description copied from class:ResourceResolve an existing Resource. -
newResource
Internal override for creating a new PathResource. Used by MountedPathResource (eg) -
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
public long length()Description copied from class:ResourceLength of the resource. -
isContainedIn
Description copied from class:ResourceReturn true if this resource is contained in the Resource r, either because r is a folder or a jar file or any form of resource capable of containing other resources.- Specified by:
isContainedInin classResource- Parameters:
r- the containing resource- Returns:
- true if this Resource is contained, false otherwise
-
copyTo
Description copied from class:ResourceCopy the Resource to the new destination file.Will not replace existing destination file.
- Overrides:
copyToin classResource- Parameters:
destination- the destination file to create- Throws:
IOException- if unable to copy 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
-