Class Resource
java.lang.Object
org.eclipse.jetty.util.resource.Resource
- Direct Known Subclasses:
 CombinedResource, MemoryResource, PathResource
- 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionbooleanReturn true if this resource deeply contains the other Resource.voidCopy the Resource to the new destination file or directory.static Stringbooleanexists()Equivalent toFiles.exists(Path, LinkOption...)with the following parameters:getPath()andLinkOption.NOFOLLOW_LINKS.Get a deep collection of contained resources.abstract StringThe file name of the resource.abstract StringgetName()The full name of the resource.abstract PathgetPath()Return the Path corresponding to this resource.Get the relative path from this Resource to a possibly contained resource.The real URI of the resource.abstract URIgetURI()URI representing the resource.booleanisAlias()booleanisContainedIn(Resource container) Return 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.abstract booleanReturn true if resource represents a directory of potential resources.abstract booleanTrue if the resource is readable.booleanisSameFile(Path path) iterator()Return an Iterator of all Resource's referenced in this Resource.The time the resource was last modified.longlength()Length of the resource.list()List of contents of a directoryResource.Creates a new input stream to the resource.Deprecated, for removal: This API element is subject to removal in a future version.abstract ResourceResolve an existing Resource.toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator 
- 
Constructor Details
- 
Resource
public Resource() 
 - 
 - 
Method Details
- 
dump
 - 
getPath
Return the Path corresponding to this resource.- Returns:
 - the path or null if there is no Path representation.
 
 - 
isContainedIn
Return 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.- Parameters:
 container- the containing resource- Returns:
 - true if this Resource is contained, false otherwise
 - See Also:
 
 - 
contains
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.- Parameters:
 other- the resource- Returns:
 - true if this Resource is deeply contains the other Resource, false otherwise
 - See Also:
 
 - 
getPathTo
Get the relative path from this Resource to a possibly contained resource.- Parameters:
 other- The other resource that may be contained in this resource- Returns:
 - a relative Path representing the path from this resource to the other resource, or null if not able to represent other resources as relative to this resource
 
 - 
iterator
Return an Iterator of all Resource's referenced in this Resource.
This is meaningful if you have a
CombinedResource, otherwise it will be a single entry Iterator of this resource. - 
exists
public boolean exists()Equivalent toFiles.exists(Path, LinkOption...)with the following parameters:getPath()andLinkOption.NOFOLLOW_LINKS.- Returns:
 - true if the represented resource exists.
 
 - 
isDirectory
public abstract boolean isDirectory()Return true if resource represents a directory of potential resources.- Returns:
 - true if the represented resource is a container/directory.
 
 - 
isReadable
public abstract boolean isReadable()True if the resource is readable.- Returns:
 - true if the represented resource exists, and can read from.
 
 - 
lastModified
The time the resource was last modified.- Returns:
 - the last modified time instant, or 
Instant.EPOCHif unable to obtain last modified. 
 - 
length
public long length()Length of the resource.- Returns:
 - the length of the resource in bytes, or -1L if unable to provide a size (such as a directory resource).
 
 - 
getURI
URI representing the resource.- Returns:
 - a URI representing the given resource, or null if there is no URI representation of the resource.
 
 - 
getName
The full name of the resource.- Returns:
 - the full name of the resource, or null if there is no name for the resource.
 
 - 
getFileName
The file name of the resource.
This is the last segment of the path.
- 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:
 
 - 
newInputStream
Creates a new input stream to the resource.- Returns:
 - an input stream to the resource or null if one is not available.
 - Throws:
 IOException- if there is a problem opening the input stream
 - 
newReadableByteChannel
@Deprecated(since="12.0.8", forRemoval=true) public ReadableByteChannel newReadableByteChannel() throws IOExceptionDeprecated, for removal: This API element is subject to removal in a future version.usenewInputStream()orIOResourcesinstead.Readable ByteChannel for the resource.- Returns:
 - a readable 
ByteChannelto the resource or null if one is not available. - Throws:
 IOException- if unable to open the readable bytechannel for the resource.
 - 
list
List of contents of a directory
Resource.Ordering is
FileSystemdependent, so callers may wish to sort the return value to ensure deterministic behavior.- Returns:
 - a mutable list of resources contained in the directory resource, or an empty immutable list if unable to build the list (e.g. the resource is not a directory or not readable).
 - See Also:
 
 - 
resolve
Resolve an existing Resource.- Parameters:
 subUriPath- the encoded subUriPath- Returns:
 - a Resource representing the requested subUriPath, which may not 
exist, or null if the resource cannot exist. - Throws:
 IllegalArgumentException- if subUriPath is invalid
 - 
isAlias
public boolean isAlias()- Returns:
 - true if this Resource is an alias to another real Resource
 
 - 
getRealURI
 - 
copyTo
Copy the Resource to the new destination file or directory.If this Resource is a File:
- And the 
destinationdoes not exist thenIO.copyFile(Path, Path)is used. - And the 
destinationis a File thenIO.copyFile(Path, Path)is used. - And the 
destinationis a Directory then a newPathreference is created in the destination with the same filename as this Resource, which is used viaIO.copyFile(Path, Path). 
If this Resource is a Directory:
- And the 
destinationdoes not exist then the destination is created as a directory viaFiles.createDirectories(Path, FileAttribute[])before theIO.copyDir(Path, Path)method is used. - And the 
destinationis a File then this results in anIllegalArgumentException. - And the 
destinationis a Directory then all files in this Resource directory tree are copied to thedestination, usingIO.copyFile(Path, Path)maintaining the same directory structure. 
If this Resource is not backed by a
Path, usenewInputStream():- And the 
destinationdoes not exist, copyInputStreamto thedestinationas a new file. - And the 
destinationis a File, copyInputStreamto the existingdestinationfile. - And the 
destinationis a Directory, copyInputStreamto a newdestinationfile in the destination directory based on this the result ofgetFileName()as the filename. 
- Parameters:
 destination- the destination file or directory to use (created if it does not exist).- Throws:
 IOException- if unable to copy the resource
 - And the 
 - 
getAllResources
Get a deep collection of contained resources.- Returns:
 - A collection of all Resources deeply contained within this resource if it is a directory, otherwise an empty collection is returned.
 
 - 
isSameFile
 - 
toString
 
 - 
 
newInputStream()orIOResourcesinstead.