public class UrlResource extends AbstractFileResolvingResource
java.net.URL
locators.
Obviously supports resolution as URL, and also as File in case of
the "file:" protocol.URL
Constructor and Description |
---|
UrlResource(String path)
Create a new UrlResource.
|
UrlResource(URI uri)
Create a new UrlResource.
|
UrlResource(URL url)
Create a new UrlResource.
|
Modifier and Type | Method and Description |
---|---|
Resource |
createRelative(String relativePath)
This implementation creates a UrlResource, applying the given path
relative to the path of the underlying URL of this resource descriptor.
|
boolean |
equals(Object obj)
This implementation compares the underlying URL references.
|
String |
getDescription()
This implementation returns a description that includes the URL.
|
File |
getFile()
This implementation returns a File reference for the underlying URL/URI,
provided that it refers to a file in the file system.
|
String |
getFilename()
This implementation returns the name of the file that this URL refers to.
|
InputStream |
getInputStream()
This implementation opens an InputStream for the given URL.
|
URI |
getURI()
This implementation returns the underlying URI directly,
if possible.
|
URL |
getURL()
This implementation returns the underlying URL reference.
|
int |
hashCode()
This implementation returns the hash code of the underlying URL reference.
|
String |
toString() |
contentLength, exists, getFile, getFileForLastModifiedCheck, isReadable, lastModified
public UrlResource(URL url)
url
- a URLpublic UrlResource(URI uri) throws MalformedURLException
uri
- a URIMalformedURLException
- if the given URL path is not validpublic UrlResource(String path) throws MalformedURLException
path
- a URL pathMalformedURLException
- if the given URL path is not validpublic InputStream getInputStream() throws IOException
false
,
mainly to avoid jar file locking on Windows.IOException
- if there is an errorURL.openConnection()
,
URLConnection.setUseCaches(boolean)
,
URLConnection.getInputStream()
public URL getURL() throws IOException
IOException
- if there is an errorpublic URI getURI() throws IOException
IOException
- if there was a problem getting the URIpublic File getFile() throws IOException
getFile
in interface Resource
getFile
in class AbstractFileResolvingResource
IOException
- if there was a problem getting the filepublic Resource createRelative(String relativePath)
relativePath
- The pathURL.URL(java.net.URL, String)
public String getFilename()
URL.getFile()
,
File.getName()
public String getDescription()
Object.toString()
public boolean equals(Object obj)
public int hashCode()