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

public abstract Class Resource

extends Object
implements Iterable<Resource>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Known Direct Subclasses
org.eclipse.jetty.util.resource.URLResourceFactory.URLResource, org.eclipse.jetty.util.resource.CombinedResource, org.eclipse.jetty.util.resource.MemoryResource, org.eclipse.jetty.util.resource.PathResource
Imports
java.io.IOException, .InputStream, .OutputStream, java.net.URI, java.nio.channels.ReadableByteChannel, java.nio.file.Files, .LinkOption, .Path, .StandardCopyOption, .StandardOpenOption, java.time.Instant, java.util.ArrayList, .Collection, .Iterator, .List, .Objects, java.util.function.BiFunction, java.util.stream.Stream, org.eclipse.jetty.util.IO, .StringUtil, .URIUtil, org.slf4j.Logger, .LoggerFactory

A Resource is a wrapper over a Path object pointing to a file or directory that can be represented by ajava.nio.file.FileSystem.

Supports real filesystems, and also ZipFS.

Field Summary

Modifier and TypeField and Description
private static final Logger
private static final LinkOption[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

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

Return true if this resource deeply contains the other Resource.

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

Copy the Resource to the new destination file or directory

public static String
dump(Resource resource)

pack-priv void
public boolean

Returns:

true if the represented resource exists.
exists
()

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

public Collection<Resource>

Returns:

A collection of all Resources deeply contained within this resource if it is a directory, otherwise an empty collection is returned.
getAllResources
()

Get a deep collection of contained resources.

public abstract String

Returns:

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

The file name of the resource.

public abstract String

Returns:

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

The full name of the resource.

public abstract Path

Returns:

the path or null if there is no Path representation.
getPath
()

Return the Path corresponding to this resource.

public Path

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
getPathTo
(Resource
The other resource that may be contained in this resource
other
)

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

public URI

Returns:

The real URI location of this resource.
getRealURI
()

The real URI of the resource.

public abstract URI

Returns:

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

URI representing the resource.

public boolean
isAlias()

Returns: true if this Resource is an alias to another real Resource

public boolean

Returns:

true if this Resource is contained, false otherwise
isContainedIn
(Resource
the containing 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.

public abstract boolean

Returns:

true if the represented resource is a container/directory.
isDirectory
()

Return true if resource represents a directory of potential resources.

public abstract boolean

Returns:

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

True if the resource is readable.

public Iterator<Resource>

Returns:

the iterator of Resources.
iterator
()

Implements java.lang.Iterable.iterator.

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

public Instant

Returns:

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

The time the resource was last modified.

public long

Returns:

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

Length of the resource.

public List<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).
list
()

List of contents of a directory Resource.

public InputStream

Returns:

an input stream to the resource or null if one is not available.
newInputStream
()

Creates a new input stream to the resource.

public ReadableByteChannel

Returns:

a readable java.nio.channels.ByteChannel to the resource or null if one is not available.
newReadableByteChannel
()

Readable ByteChannel for the resource.

public abstract Resource

Returns:

an existing Resource representing the requested subUriPath, or null if resource does not exist.
resolve
(String
the encoded subUriPath
subUriPath
)

Resolve an existing Resource.

pack-priv static Path
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGback to summary
private static final Logger LOG

Constructor Detail

Resourceback to summary
public Resource()

Method Detail

containsback to summary
public boolean contains(Resource other)

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

See Also
isContainedIn(Resource)
copyToback to summary
public void copyTo(Path destination) throws IOException

Copy the Resource to the new destination file or directory

Parameters
destination:Path

the destination file to create or directory to use.

Exceptions
IOException:
if unable to copy the resource
dumpback to summary
public static String dump(Resource resource)
ensureDirExistsback to summary
pack-priv void ensureDirExists(Path dir) throws IOException
existsback to summary
public boolean exists()

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

Returns:boolean

true if the represented resource exists.

getAllResourcesback to summary
public Collection<Resource> getAllResources()

Get a deep collection of contained resources.

Returns:Collection<Resource>

A collection of all Resources deeply contained within this resource if it is a directory, otherwise an empty collection is returned.

getFileNameback to summary
public abstract String 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.

See Also
Path#getFileName()
getNameback to summary
public abstract String 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.

getPathback to summary
public abstract Path getPath()

Return the Path corresponding to this resource.

Returns:Path

the path or null if there is no Path representation.

getPathToback to summary
public Path getPathTo(Resource other)

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

getRealURIback to summary
public URI getRealURI()

The real URI of the resource.

If this Resource is an alias, (isAlias()), this URI will be different from getURI(), and will point to the real name/location of the Resource.

Returns:URI

The real URI location of this resource.

getURIback to summary
public abstract URI getURI()

URI representing the resource.

Returns:URI

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

isAliasback to summary
public boolean isAlias()
Returns:boolean

true if this Resource is an alias to another real Resource

isContainedInback to summary
public boolean isContainedIn(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.

Parameters
container:Resource

the containing resource

Returns:boolean

true if this Resource is contained, false otherwise

See Also
contains(Resource)
isDirectoryback to summary
public abstract boolean isDirectory()

Return true if resource represents a directory of potential resources.

Returns:boolean

true if the represented resource is a container/directory.

isReadableback to summary
public abstract boolean isReadable()

True if the resource is readable.

Returns:boolean

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

iteratorback to summary
public Iterator<Resource> iterator()

Implements java.lang.Iterable.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()

The time the resource was last modified.

Returns:Instant

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

lengthback to summary
public long 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).

listback to summary
public List<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).

See Also
Resource#isDirectory(), Resource#isReadable()
newInputStreamback to summary
public InputStream newInputStream() throws IOException

Creates a new input stream to the resource.

Returns:InputStream

an input stream to the resource or null if one is not available.

Exceptions
IOException:
if there is a problem opening the input stream
newReadableByteChannelback to summary
public ReadableByteChannel newReadableByteChannel() throws IOException

Readable ByteChannel for the resource.

Returns:ReadableByteChannel

a readable java.nio.channels.ByteChannel to the resource or null if one is not available.

Exceptions
IOException:
if unable to open the readable bytechannel for the resource.
resolveback to summary
public abstract Resource resolve(String subUriPath)

Resolve an existing Resource.

Parameters
subUriPath:String

the encoded subUriPath

Returns:Resource

an existing Resource representing the requested subUriPath, or null if resource does not exist.

Exceptions
IllegalArgumentException:
if subUriPath is invalid
resolveDifferentFileSystemback to summary
pack-priv static Path resolveDifferentFileSystem(Path path, Path relative)