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
Modifier and TypeFieldDescriptionprotected URLConnection
protected InputStream
protected final AutoLock
protected final URL
protected final String
Fields inherited from class org.eclipse.jetty.util.resource.Resource
__defaultUseCaches
-
Constructor Summary
ModifierConstructorDescriptionprotected
URLResource
(URL url, URLConnection connection) protected
URLResource
(URL url, URLConnection connection, boolean useCaches) -
Method Summary
Modifier and TypeMethodDescriptionReturns the resource contained inside the current resource with the given nameprotected boolean
void
close()
Release any resources held by the resource.boolean
delete()
Deletes the given resourceboolean
boolean
exists()
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 InputStream
getInputStream
(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 resourceboolean
int
hashCode()
boolean
isContainedIn
(Resource containingResource) boolean
long
Returns the last modified timelong
length()
Return the length of the resourceString[]
list()
Returns a list of resource names contained in the given resourceboolean
Rename 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:
isDirectory
in classResource
- Returns:
- true if the represented resource is a container/directory.
-
lastModified
public long lastModified()Returns the last modified time- Specified by:
lastModified
in 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:
getFile
in 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:
getInputStream
in 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:Resource
Readable ByteChannel for the resource.- Specified by:
getReadableByteChannel
in 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:
delete
in 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:
renameTo
in 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:
addPath
in 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:
isContainedIn
in classResource
- Throws:
MalformedURLException
-