Package org.eclipse.jetty.util.resource
Class URLResource
java.lang.Object
org.eclipse.jetty.util.resource.Resource
org.eclipse.jetty.util.resource.URLResource
- All Implemented Interfaces:
Closeable,AutoCloseable,ResourceFactory
- Direct Known Subclasses:
JarResource
URL resource class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected URLConnectionprotected InputStreamprotected final AutoLockprotected final URLprotected final StringFields inherited from class org.eclipse.jetty.util.resource.Resource
__defaultUseCaches -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedURLResource(URL url, URLConnection connection) protectedURLResource(URL url, URLConnection connection, boolean useCaches) -
Method Summary
Modifier and TypeMethodDescriptionReturns the resource contained inside the current resource with the given nameprotected booleanvoidclose()Release any resources held by the resource.booleandelete()Deletes the given resourcebooleanbooleanexists()Returns true if the represented resource exists.getFile()Returns an File representing the given resource or NULL if this is not possible.Returns an input stream to the resource.protected InputStreamgetInputStream(boolean resetConnection) Returns an input stream to the resource, optionally nulling out the underlying url connection.getName()Returns the name of the resourceReadable ByteChannel for the resource.getURI()Returns a URI representing the given resourcebooleaninthashCode()booleanisContainedIn(Resource containingResource) booleanlongReturns the last modified timelonglength()Return the length of the resourceString[]list()Returns a list of resource names contained in the given resourcebooleanRename the given resourcetoString()Methods inherited from class org.eclipse.jetty.util.resource.Resource
copyTo, fromList, fromList, getAlias, getAllResources, getAssociate, getDefaultUseCaches, getListHTML, getResource, getWeakETag, getWeakETag, isAlias, isContainedIn, isSame, newClassPathResource, newClassPathResource, newResource, newResource, newResource, newResource, newResource, newResource, newSystemResource, resolveAlias, setAssociate, setDefaultUseCaches, toURL
-
Field Details
-
_lock
-
_url
-
_urlString
-
_connection
-
_in
-
-
Constructor Details
-
URLResource
-
URLResource
-
-
Method Details
-
checkConnection
protected boolean checkConnection() -
close
public void close()Release any resources held by the resource. -
exists
public boolean exists()Returns true if the represented resource exists. -
isDirectory
public boolean isDirectory()- Specified by:
isDirectoryin classResource- Returns:
- true if the represented resource is a container/directory.
-
lastModified
public long lastModified()Returns the last modified time- Specified by:
lastModifiedin classResource- Returns:
- the last modified time as milliseconds since unix epoch
-
length
public long length()Return the length of the resource -
getURI
Returns a URI representing the given resource -
getFile
Returns an File representing the given resource or NULL if this is not possible.- Specified by:
getFilein classResource- 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
Returns the name of the resource -
getInputStream
Returns an input stream to the resource. The underlying url connection will be nulled out to prevent re-use.- Specified by:
getInputStreamin classResource- Returns:
- an input stream to the resource
- Throws:
IOException- if unable to open the input stream
-
getInputStream
Returns an input stream to the resource, optionally nulling out the underlying url connection. If the connection is not nulled out, a subsequent call to getInputStream() may return an existing and already in-use input stream - this depends on the url protocol. Eg JarURLConnection does not reuse inputstreams.- Parameters:
resetConnection- if true the connection field is set to null- Returns:
- the inputstream for this resource
- Throws:
IOException- if unable to open the input stream
-
getReadableByteChannel
Description copied from class:ResourceReadable ByteChannel for the resource.- Specified by:
getReadableByteChannelin classResource- 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
Deletes the given resource- Specified by:
deletein classResource- 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
Rename the given resource- Specified by:
renameToin classResource- 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
Returns a list of resource names contained in the given resource -
addPath
Returns the resource contained inside the current resource with the given name- Specified by:
addPathin classResource- 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 fromResource.isAlias().- Returns:
- the Resource for the resolved path within this Resource, never null
- 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.
-
toString
-
hashCode
public int hashCode() -
equals
-
getUseCaches
public boolean getUseCaches() -
isContainedIn
- Specified by:
isContainedInin classResource- Throws:
MalformedURLException
-