Top Description Fields Constructors Methods
org.eclipse.jetty.util.resource

public Class CombinedResource

extends Resource
Class Inheritance
Imports
java.io.IOException, .InputStream, .OutputStream, java.net.URI, java.nio.file.Files, .Path, .StandardCopyOption, java.time.Instant, java.util.ArrayList, .Collection, .Collections, .Iterator, .List, .Map, .Objects, .TreeMap, java.util.stream.Collectors, org.eclipse.jetty.util.IO, .URIUtil

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

Field Summary

Modifier and TypeField and Description
private final List<Resource>

Constructor Summary

AccessConstructor and Description
pack-priv
CombinedResource(List<Resource>
the resources to be added to collection
resources
)

Instantiates a new resource collection.

Method Summary

Modifier and TypeMethod and Description
pack-priv static Resource

Returns:

A Resource of multiple resources or a single resource if only 1 is passed, or null if none are passed. Any Resource returned will always return true from Resource#isDirectory()
combine
(List<Resource>
multiple directory resources to combine as a single resource. Order is significant.
resources
)

Make a Resource containing a combination of multiple directory resources.

public boolean
contains(Resource
the resource
other
)

Overrides org.eclipse.jetty.util.resource.Resource.contains.

Return true if this resource deeply contains the other Resource.

public void
copyTo(Path
the destination file to create or directory to use.
destination
)

Overrides org.eclipse.jetty.util.resource.Resource.copyTo.

Copy the Resource to the new destination file or directory

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public boolean
pack-priv static List<Resource>
public String
getFileName()

Implements abstract org.eclipse.jetty.util.resource.Resource.getFileName.

The file name of the resource.

public String
getName()

Implements abstract org.eclipse.jetty.util.resource.Resource.getName.

The full name of the resource.

public Path
getPath()

Implements abstract org.eclipse.jetty.util.resource.Resource.getPath.

Return the Path corresponding to this resource.

public Path
getPathTo(Resource
The other resource that may be contained in this resource
other
)

Overrides org.eclipse.jetty.util.resource.Resource.getPathTo.

Get the relative path from this Resource to a possibly contained resource.

public List<Resource>

Returns:

the resource collection
getResources
()

Retrieves the resource collection's resources.

public URI
getURI()

Implements abstract org.eclipse.jetty.util.resource.Resource.getURI.

URI representing the resource.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
isDirectory()

Implements abstract org.eclipse.jetty.util.resource.Resource.isDirectory.

Return true if resource represents a directory of potential resources.

public boolean
isReadable()

Implements abstract org.eclipse.jetty.util.resource.Resource.isReadable.

True if the resource is readable.

public Iterator<Resource>
iterator()

Overrides org.eclipse.jetty.util.resource.Resource.iterator.

Implements java.lang.Iterable.iterator.

Return an Iterator of all Resource's referenced in this Resource.

public Instant
lastModified()

Overrides org.eclipse.jetty.util.resource.Resource.lastModified.

The time the resource was last modified.

public long
length()

Overrides org.eclipse.jetty.util.resource.Resource.length.

Length of the resource.

public List<Resource>
list()

Overrides org.eclipse.jetty.util.resource.Resource.list.

List of contents of a directory Resource.

public Resource

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
resolve
(String
The path segment to resolve
subUriPath
)

Implements abstract org.eclipse.jetty.util.resource.Resource.resolve.

Resolves a path against the resource collection.

public String

Returns:

the list of resources
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.eclipse.jetty.util.resource.Resource:
dumpensureDirExistsgetAllResourcesgetRealURIisAliasisContainedInnewInputStreamnewReadableByteChannelresolveDifferentFileSystem

Field Detail

_resourcesback to summary
private final List<Resource> _resources

Constructor Detail

CombinedResourceback to summary
pack-priv CombinedResource(List<Resource> resources)

Instantiates a new resource collection.

Parameters
resources:List<Resource>

the resources to be added to collection

Method Detail

combineback to summary
pack-priv static Resource combine(List<Resource> resources)

Make a Resource containing a combination of multiple directory resources.

Parameters
resources:List<Resource>

multiple directory resources to combine as a single resource. Order is significant.

Returns:Resource

A Resource of multiple resources or a single resource if only 1 is passed, or null if none are passed. Any Resource returned will always return true from Resource#isDirectory()

Exceptions
IllegalArgumentException:
if a non-directory resource is passed.
See Also
CombinedResource
containsback to summary
public boolean contains(Resource other)

Overrides org.eclipse.jetty.util.resource.Resource.contains.

Doc from org.eclipse.jetty.util.resource.Resource.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:Resource

the resource

Returns:boolean

true if this Resource is deeply contains the other Resource, false otherwise

Annotations
@Override
copyToback to summary
public void copyTo(Path destination) throws IOException

Overrides org.eclipse.jetty.util.resource.Resource.copyTo.

Doc from org.eclipse.jetty.util.resource.Resource.copyTo.

Copy the Resource to the new destination file or directory

Parameters
destination:Path

the destination file to create or directory to use.

Annotations
@Override
Exceptions
IOException:
if unable to copy the resource
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
existsback to summary
public boolean exists()

Overrides org.eclipse.jetty.util.resource.Resource.exists.

Doc from org.eclipse.jetty.util.resource.Resource.exists.

Equivalent to Files#exists(Path, LinkOption...) with the following parameters: getPath() and LinkOption#NOFOLLOW_LINKS.

Returns:boolean

true if the represented resource exists.

Annotations
@Override
gatherUniqueFlatResourceListback to summary
pack-priv static List<Resource> gatherUniqueFlatResourceList(List<Resource> resources)
getFileNameback to summary
public String getFileName()

Implements abstract org.eclipse.jetty.util.resource.Resource.getFileName.

Doc from org.eclipse.jetty.util.resource.Resource.getFileName.

The file name of the resource.

This is the last segment of the path.

Returns:String

the filename of the resource, or "" if there are no path segments (eg: path of "/"), or null if resource cannot determine a filename.

Annotations
@Override
getNameback to summary
public String getName()

Implements abstract org.eclipse.jetty.util.resource.Resource.getName.

Doc from org.eclipse.jetty.util.resource.Resource.getName.

The full name of the resource.

Returns:String

the full name of the resource, or null if there is no name for the resource.

Annotations
@Override
getPathback to summary
public Path getPath()

Implements abstract org.eclipse.jetty.util.resource.Resource.getPath.

Doc from org.eclipse.jetty.util.resource.Resource.getPath.

Return the Path corresponding to this resource.

Returns:Path

the path or null if there is no Path representation.

Annotations
@Override
getPathToback to summary
public Path getPathTo(Resource other)

Overrides org.eclipse.jetty.util.resource.Resource.getPathTo.

Doc from org.eclipse.jetty.util.resource.Resource.getPathTo.

Get the relative path from this Resource to a possibly contained resource.

Parameters
other:Resource

The other resource that may be contained in this resource

Returns:Path

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

Annotations
@Override
getResourcesback to summary
public List<Resource> getResources()

Retrieves the resource collection's resources.

Returns:List<Resource>

the resource collection

getURIback to summary
public URI getURI()

Implements abstract org.eclipse.jetty.util.resource.Resource.getURI.

Doc from org.eclipse.jetty.util.resource.Resource.getURI.

URI representing the resource.

Returns:URI

a URI representing the given resource, or null if there is no URI representation of the resource.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isDirectoryback to summary
public boolean isDirectory()

Implements abstract org.eclipse.jetty.util.resource.Resource.isDirectory.

Doc from org.eclipse.jetty.util.resource.Resource.isDirectory.

Return true if resource represents a directory of potential resources.

Returns:boolean

true if the represented resource is a container/directory.

Annotations
@Override
isReadableback to summary
public boolean isReadable()

Implements abstract org.eclipse.jetty.util.resource.Resource.isReadable.

Doc from org.eclipse.jetty.util.resource.Resource.isReadable.

True if the resource is readable.

Returns:boolean

true if the represented resource exists, and can read from.

Annotations
@Override
iteratorback to summary
public Iterator<Resource> iterator()

Overrides org.eclipse.jetty.util.resource.Resource.iterator.

Implements java.lang.Iterable.iterator.

Doc from org.eclipse.jetty.util.resource.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.

Returns:Iterator<Resource>

the iterator of Resources.

Annotations
@Override
lastModifiedback to summary
public Instant lastModified()

Overrides org.eclipse.jetty.util.resource.Resource.lastModified.

Doc from org.eclipse.jetty.util.resource.Resource.lastModified.

The time the resource was last modified.

Returns:Instant

the last modified time instant, or Instant#EPOCH if unable to obtain last modified.

Annotations
@Override
lengthback to summary
public long length()

Overrides org.eclipse.jetty.util.resource.Resource.length.

Doc from org.eclipse.jetty.util.resource.Resource.length.

Length of the resource.

Returns:long

the length of the resource in bytes, or -1L if unable to provide a size (such as a directory resource).

Annotations
@Override
listback to summary
public List<Resource> list()

Overrides org.eclipse.jetty.util.resource.Resource.list.

Doc from org.eclipse.jetty.util.resource.Resource.list.

List of contents of a directory Resource.

Ordering is java.nio.file.FileSystem dependent, so callers may wish to sort the return value to ensure deterministic behavior.

Returns:List<Resource>

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).

Annotations
@Override
resolveback to summary
public Resource resolve(String subUriPath)

Implements abstract org.eclipse.jetty.util.resource.Resource.resolve.

Resolves a path against the resource collection.

Parameters
subUriPath:String

The path segment to resolve

Returns:Resource

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
Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

the list of resources

Annotations
@Override