Class UrlResource
java.lang.Object
nl.basjes.parse.useragent.utils.springframework.core.io.AbstractResource
nl.basjes.parse.useragent.utils.springframework.core.io.AbstractFileResolvingResource
nl.basjes.parse.useragent.utils.springframework.core.io.UrlResource
- All Implemented Interfaces:
InputStreamSource,Resource
- Direct Known Subclasses:
FileUrlResource
{link Resource} implementation for
java.net.URL locators.
Supports resolution as a URL and also as a File in
case of the "file:" protocol.- Since:
- 28.12.2003
- Author:
- Juergen Hoeller see java.net.URL
-
Constructor Summary
ConstructorsConstructorDescriptionUrlResource(String path) Create a newUrlResourcebased on a URL path.UrlResource(URL url) Create a newUrlResourcebased on the given URL object. -
Method Summary
Modifier and TypeMethodDescriptioncreateRelative(String relativePath) This implementation creates aUrlResource, delegating to {link #createRelativeURL(String)} for adapting the relative path.protected URLcreateRelativeURL(String relativePath) This delegate creates ajava.net.URL, applying the given path relative to the path of the underlying URL of this resource descriptor.booleanThis implementation compares the underlying URL references.This implementation returns a description that includes the URL.getFile()This implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.This implementation returns the name of the file that this URL refers to.This implementation opens an InputStream for the given URL.getURI()This implementation returns the underlying URI directly, if possible.getURL()This implementation returns the underlying URL reference.inthashCode()This implementation returns the hash code of the underlying URL reference.booleanisFile()This implementation always returnsfalse.Methods inherited from class nl.basjes.parse.useragent.utils.springframework.core.io.AbstractFileResolvingResource
contentLength, customizeConnection, customizeConnection, exists, getFile, isFileMethods inherited from class nl.basjes.parse.useragent.utils.springframework.core.io.AbstractResource
isOpen, toString
-
Constructor Details
-
UrlResource
Create a newUrlResourcebased on the given URL object.- Parameters:
url- a URL see #UrlResource(URI) see #UrlResource(String)
-
UrlResource
Create a newUrlResourcebased on a URL path.Note: The given path needs to be pre-encoded if necessary.
- Parameters:
path- a URL path- Throws:
MalformedURLException- if the given URL path is not valid see java.net.URL#URL(String)
-
-
Method Details
-
getInputStream
This implementation opens an InputStream for the given URL.It sets the
useCachesflag tofalse, mainly to avoid jar file locking on Windows. see java.net.URL#openConnection() see java.net.URLConnection#setUseCaches(boolean) see java.net.URLConnection#getInputStream()- Returns:
- the input stream for the underlying resource (must not be
null) - Throws:
IOException- if the content stream could not be opened see Resource#isReadable()
-
getURL
This implementation returns the underlying URL reference.- Specified by:
getURLin interfaceResource- Overrides:
getURLin classAbstractResource
-
getURI
This implementation returns the underlying URI directly, if possible.- Specified by:
getURIin interfaceResource- Overrides:
getURIin classAbstractResource- Throws:
IOException- if the resource cannot be resolved as URI, i.e. if the resource is not available as a descriptor
-
isFile
public boolean isFile()Description copied from class:AbstractResourceThis implementation always returnsfalse.- Specified by:
isFilein interfaceResource- Overrides:
isFilein classAbstractFileResolvingResource
-
getFile
This implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system. see org.springframework.util.ResourceUtils#getFile(java.net.URL, String)- Specified by:
getFilein interfaceResource- Overrides:
getFilein classAbstractFileResolvingResource- Throws:
IOException- in case of general resolution/reading failures see #getInputStream()
-
createRelative
This implementation creates aUrlResource, delegating to {link #createRelativeURL(String)} for adapting the relative path. see #createRelativeURL(String)- Specified by:
createRelativein interfaceResource- Overrides:
createRelativein classAbstractResource- Parameters:
relativePath- the relative path (relative to this resource)- Returns:
- the resource handle for the relative resource
- Throws:
MalformedURLException
-
createRelativeURL
This delegate creates ajava.net.URL, applying the given path relative to the path of the underlying URL of this resource descriptor. A leading slash will get dropped; a "#" symbol will get encoded. see #createRelative(String) see java.net.URL#URL(java.net.URL, String)- Throws:
MalformedURLException- Since:
- 5.2
-
getFilename
This implementation returns the name of the file that this URL refers to. see java.net.URL#getPath()- Specified by:
getFilenamein interfaceResource- Overrides:
getFilenamein classAbstractResource
-
getDescription
This implementation returns a description that includes the URL. -
equals
This implementation compares the underlying URL references.- Overrides:
equalsin classAbstractResource
-
hashCode
public int hashCode()This implementation returns the hash code of the underlying URL reference.- Overrides:
hashCodein classAbstractResource
-