Class CombinedResource

java.lang.Object
org.eclipse.jetty.util.resource.Resource
org.eclipse.jetty.util.resource.CombinedResource
All Implemented Interfaces:
Iterable<Resource>

public class CombinedResource extends Resource
Multiple Resource directories presented as a single overlayed Resource directory.

This class differs from a List<Resource>, as a relative path can resolve to only a single Resource in a CombinedResource, whilst it may resolve to multiple in a List<Resource>.

  • Method Details

    • getResources

      public List<Resource> getResources()
      Retrieves the resource collection's resources.
      Returns:
      the resource collection
    • resolve

      public Resource resolve(String subUriPath)
      Resolves a path against the resource collection.
      Specified by:
      resolve in class Resource
      Parameters:
      subUriPath - The path segment to resolve
      Returns:
      The resulting resource :
      • is a file that exists in at least one of the collection, then the first one found is returned
      • is a directory that exists in at exactly one of the collection, then that simple directory resource is returned
      • is a directory that exists in several of the collection, then a ResourceCollection of those directories is returned
      • is null if not found in any entry in this collection
    • exists

      public boolean exists()
      Description copied from class: Resource
      Equivalent to Files.exists(Path, LinkOption...) with the following parameters: Resource.getPath() and LinkOption.NOFOLLOW_LINKS.
      Overrides:
      exists in class Resource
      Returns:
      true if the represented resource exists.
    • getPath

      public Path getPath()
      Description copied from class: Resource
      Return the Path corresponding to this resource.
      Specified by:
      getPath in class Resource
      Returns:
      the path or null if there is no Path representation.
    • getName

      public String getName()
      Description copied from class: Resource
      The full name of the resource.
      Specified by:
      getName in class Resource
      Returns:
      the full name of the resource, or null if there is no name for the resource.
    • getFileName

      public String getFileName()
      Description copied from class: Resource

      The file name of the resource.

      This is the last segment of the path.

      Specified by:
      getFileName in class Resource
      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

      public URI getURI()
      Description copied from class: Resource
      URI representing the resource.
      Specified by:
      getURI in class Resource
      Returns:
      a URI representing the given resource, or null if there is no URI representation of the resource.
    • isDirectory

      public boolean isDirectory()
      Description copied from class: Resource
      Return true if resource represents a directory of potential resources.
      Specified by:
      isDirectory in class Resource
      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 class Resource
      Returns:
      true if the represented resource exists, and can read from.
    • lastModified

      public Instant lastModified()
      Description copied from class: Resource
      The time the resource was last modified.
      Overrides:
      lastModified in class Resource
      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.
      Overrides:
      length in class Resource
      Returns:
      the length of the resource in bytes, or -1L if unable to provide a size (such as a directory resource).
    • iterator

      public Iterator<Resource> iterator()
      Description copied from class: Resource

      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.

      Specified by:
      iterator in interface Iterable<Resource>
      Overrides:
      iterator in class Resource
      Returns:
      the iterator of Resources.
    • list

      public List<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.

      Overrides:
      list in class Resource
      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:
    • copyTo

      public void copyTo(Path destination) throws IOException
      Description copied from class: Resource
      Copy the Resource to the new destination file or directory.

      If this Resource is a File:

      If this Resource is a Directory:

      If this Resource is not backed by a Path, use Resource.newInputStream():

      • And the destination does not exist, copy InputStream to the destination as a new file.
      • And the destination is a File, copy InputStream to the existing destination file.
      • And the destination is a Directory, copy InputStream to a new destination file in the destination directory based on this the result of Resource.getFileName() as the filename.
      Overrides:
      copyTo in class Resource
      Parameters:
      destination - the destination file or directory to use (created if it does not exist).
      Throws:
      IOException - if unable to copy the resource
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • isAlias

      public boolean isAlias()
      Overrides:
      isAlias in class Resource
      Returns:
      true if this Resource is an alias to another real Resource
    • getRealURI

      public URI 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 from Resource.getURI(), and will point to the real name/location of the Resource.

      Overrides:
      getRealURI in class Resource
      Returns:
      The real URI location of this resource.
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      the list of resources
    • contains

      public boolean contains(Resource other)
      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.
      Overrides:
      contains in class Resource
      Parameters:
      other - the resource
      Returns:
      true if this Resource is deeply contains the other Resource, false otherwise
      See Also:
    • getPathTo

      public Path getPathTo(Resource other)
      Description copied from class: Resource
      Get the relative path from this Resource to a possibly contained resource.
      Overrides:
      getPathTo in class 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
    • isSameFile

      public boolean isSameFile(Path path)
      Overrides:
      isSameFile in class Resource