Package org.eclipse.jetty.util.resource
Class Resource
java.lang.Object
org.eclipse.jetty.util.resource.Resource
- All Implemented Interfaces:
Closeable,AutoCloseable,ResourceFactory
- Direct Known Subclasses:
EmptyResource,FileResource,PathResource,ResourceCollection,URLResource
@Deprecated(since="2021-05-27")
public abstract class Resource
extends Object
implements ResourceFactory, Closeable
Deprecated.
The Eclipse Jetty and Apache Felix Http Jetty packages are no longer supported.
Abstract resource class.
This class provides a resource abstraction, where a resource may be a file, a URL or an entry in a jar file.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract ResourceDeprecated.Returns the resource contained inside the current resource with the given name.abstract voidclose()Deprecated.Release any temporary resources held by the resource.voidDeprecated.Copy the Resource to the new destination file.abstract booleandelete()Deprecated.Deletes the given resourceDeprecated.useURIUtilorUrlEncodedinsteadabstract booleanexists()Deprecated.getAlias()Deprecated.Deprecated.Deprecated.static booleanDeprecated.abstract FilegetFile()Deprecated.File representing the given resource.abstract InputStreamDeprecated.Input stream to the resourcegetListHTML(String base, boolean parent) Deprecated.usegetListHTML(String, boolean, String)instead and supply raw query string.getListHTML(String base, boolean parent, String query) Deprecated.Get the resource list as a HTML directory listing.abstract StringgetName()Deprecated.The name of the resource.abstract ReadableByteChannelDeprecated.Readable ByteChannel for the resource.getResource(String path) Deprecated.Get a resource from within this resource.getURI()Deprecated.URI representing the resource.abstract URLgetURL()Deprecated.use {getURI().toURL() instead.Deprecated.Generate a weak ETag reference for this Resource.getWeakETag(String suffix) Deprecated.booleanisAlias()Deprecated.abstract booleanDeprecated.static booleanisContainedIn(Resource r, Resource containingResource) Deprecated.abstract booleanDeprecated.booleanDeprecated.Return true if the passed Resource represents the same resource as the Resource.abstract longDeprecated.Time resource was last modified.abstract longlength()Deprecated.Length of the resource.abstract String[]list()Deprecated.list of resource names contained in the given resource.static ResourcenewClassPathResource(String resource) Deprecated.Find a classpath resource.static ResourcenewClassPathResource(String name, boolean useCaches, boolean checkParents) Deprecated.Find a classpath resource.static ResourcenewResource(File file) Deprecated.static ResourcenewResource(String resource) Deprecated.Construct a resource from a string.static ResourcenewResource(String resource, boolean useCaches) Deprecated.Construct a resource from a string.static ResourcenewResource(URI uri) Deprecated.Construct a resource from a uri.static ResourcenewResource(URL url) Deprecated.Construct a resource from a url.static ResourcenewResource(Path path) Deprecated.Construct a Resource from provided pathstatic ResourcenewSystemResource(String resource) Deprecated.Construct a system resource from a string.final voidrelease()Deprecated.useclose()abstract booleanDeprecated.Rename the given resourcevoidDeprecated.static voidsetDefaultUseCaches(boolean useCaches) Deprecated.Change the default setting for url connection caches.static URLDeprecated.Generate a properly encoded URL from aFileinstance.voidwriteTo(OutputStream out, long start, long count) Deprecated.
-
Field Details
-
__defaultUseCaches
public static boolean __defaultUseCachesDeprecated.
-
-
Constructor Details
-
Resource
public Resource()Deprecated.
-
-
Method Details
-
setDefaultUseCaches
public static void setDefaultUseCaches(boolean useCaches) Deprecated.Change the default setting for url connection caches. Subsequent URLConnections will use this default.- Parameters:
useCaches- true to enable URL connection caches, false otherwise.
-
getDefaultUseCaches
public static boolean getDefaultUseCaches()Deprecated. -
newResource
Deprecated.Construct a resource from a uri.- Parameters:
uri- A URI.- Returns:
- A Resource object.
- Throws:
MalformedURLException- Problem accessing URI
-
newResource
Deprecated.Construct a resource from a url.- Parameters:
url- A URL.- Returns:
- A Resource object.
-
newResource
Deprecated.Construct a resource from a string.- Parameters:
resource- A URL or filename.- Returns:
- A Resource object.
- Throws:
MalformedURLException- Problem accessing URIIOException
-
newResource
Deprecated.Construct a resource from a string.- Parameters:
resource- A URL or filename.useCaches- controls URLConnection caching- Returns:
- A Resource object.
- Throws:
MalformedURLException- Problem accessing URIIOException
-
newResource
Deprecated. -
newResource
Deprecated.Construct a Resource from provided path- Parameters:
path- the path- Returns:
- the Resource for the provided path
- Since:
- 9.4.10
-
newSystemResource
Deprecated.Construct a system resource from a string. The resource is tried as classloader resource before being treated as a normal resource.- Parameters:
resource- Resource as string representation- Returns:
- The new Resource
- Throws:
IOException- Problem accessing resource.
-
newClassPathResource
Deprecated.Find a classpath resource.- Parameters:
resource- the relative name of the resource- Returns:
- Resource or null
-
newClassPathResource
Deprecated.Find a classpath resource. TheClass.getResource(String)method is used to lookup the resource. If it is not found, then theLoader.getResource(String)method is used. If it is still not found, thenClassLoader.getSystemResource(String)is used. UnlikeClassLoader.getSystemResource(String)this method does not check for normal resources.- Parameters:
name- The relative name of the resourceuseCaches- True if URL caches are to be used.checkParents- True if forced searching of parent Classloaders is performed to work around loaders with inverted priorities- Returns:
- Resource or null
-
isContainedIn
public static boolean isContainedIn(Resource r, Resource containingResource) throws MalformedURLException Deprecated.- Throws:
MalformedURLException
-
isContainedIn
Deprecated.- Throws:
MalformedURLException
-
isSame
Deprecated.Return true if the passed Resource represents the same resource as the Resource. For many resource types, this is equivalent toObject.equals(Object), however for resources types that support aliasing, this maybe some other check (e.g.Files.isSameFile(Path, Path)).- Parameters:
resource- The resource to check- Returns:
- true if the passed resource represents the same resource.
-
release
public final void release()Deprecated.useclose()Release any temporary resources held by the resource. -
close
public abstract void close()Deprecated.Release any temporary resources held by the resource.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
exists
public abstract boolean exists()Deprecated.- Returns:
- true if the represented resource exists.
-
isDirectory
public abstract boolean isDirectory()Deprecated.- Returns:
- true if the represented resource is a container/directory. if the resource is not a file, resources ending with "/" are considered directories.
-
lastModified
public abstract long lastModified()Deprecated.Time resource was last modified.- Returns:
- the last modified time as milliseconds since unix epoch
-
length
public abstract long length()Deprecated.Length of the resource.- Returns:
- the length of the resource
-
getURL
Deprecated.use {getURI().toURL() instead.URL representing the resource.- Returns:
- a URL representing the given resource
-
getURI
Deprecated.URI representing the resource.- Returns:
- an URI representing the given resource
-
getFile
Deprecated.File representing the given resource.- Returns:
- an File representing the given resource or NULL if this is not possible.
- Throws:
IOException- if unable to get the resource due to permissions
-
getName
Deprecated.The name of the resource.- Returns:
- the name of the resource
-
getInputStream
Deprecated.Input stream to the resource- Returns:
- an input stream to the resource
- Throws:
IOException- if unable to open the input stream
-
getReadableByteChannel
Deprecated.Readable ByteChannel for the resource.- Returns:
- an readable bytechannel to the resource or null if one is not available.
- Throws:
IOException- if unable to open the readable bytechannel for the resource.
-
delete
Deprecated.Deletes the given resource- Returns:
- true if resource was found and successfully deleted, false if resource didn't exist or was unable to be deleted.
- Throws:
SecurityException- if unable to delete due to permissions
-
renameTo
Deprecated.Rename the given resource- Parameters:
dest- the destination name for the resource- Returns:
- true if the resource was renamed, false if the resource didn't exist or was unable to be renamed.
- Throws:
SecurityException- if unable to rename due to permissions
-
list
Deprecated.list of resource names contained in the given resource. Ordering is unspecified, so callers may wish to sort the return value to ensure deterministic behavior.- Returns:
- a list of resource names contained in the given resource, or null. Note: The resource names are not URL encoded.
-
addPath
Deprecated.Returns the resource contained inside the current resource with the given name.- Parameters:
path- The path segment to add, which is not encoded. The path may be non canonical, but if so then the resulting Resource will return true fromisAlias().- Returns:
- the Resource for the resolved path within this Resource.
- Throws:
IOException- if unable to resolve the pathMalformedURLException- if the resolution of the path fails because the input path parameter is malformed, or a relative path attempts to access above the root resource.
-
getResource
Deprecated.Get a resource from within this resource.This method is essentially an alias for
addPath(String), but without checked exceptions. This method satisfied theResourceFactoryinterface.- Specified by:
getResourcein interfaceResourceFactory- Parameters:
path- The path to the resource- Returns:
- The resource or null
- See Also:
-
encode
Deprecated.useURIUtilorUrlEncodedinstead- Parameters:
uri- the uri to encode- Returns:
- null (this is deprecated)
-
getAssociate
Deprecated. -
setAssociate
Deprecated. -
isAlias
public boolean isAlias()Deprecated.- Returns:
- true if this Resource is an alias to another real Resource
-
getAlias
Deprecated.- Returns:
- The canonical Alias of this resource or null if none.
-
getListHTML
Deprecated.usegetListHTML(String, boolean, String)instead and supply raw query string.Get the resource list as a HTML directory listing.- Parameters:
base- The base URLparent- True if the parent directory should be included- Returns:
- String of HTML
- Throws:
IOException- if unable to get the list of resources as HTML
-
getListHTML
Deprecated.Get the resource list as a HTML directory listing.- Parameters:
base- The base URLparent- True if the parent directory should be includedquery- query params- Returns:
- String of HTML
- Throws:
IOException
-
writeTo
Deprecated.- Parameters:
out- the output stream to write tostart- First byte to writecount- Bytes to write or -1 for all of them.- Throws:
IOException- if unable to copy the Resource to the output
-
copyTo
Deprecated.Copy the Resource to the new destination file.Will not replace existing destination file.
- Parameters:
destination- the destination file to create- Throws:
IOException- if unable to copy the resource
-
getWeakETag
Deprecated.Generate a weak ETag reference for this Resource.- Returns:
- the weak ETag reference for this resource.
-
getWeakETag
Deprecated. -
getAllResources
Deprecated. -
toURL
Deprecated.Generate a properly encoded URL from aFileinstance.- Parameters:
file- Target file.- Returns:
- URL of the target file.
- Throws:
MalformedURLException- if unable to convert File to URL
-