Package org.grails.io.support
Class UrlResource
- java.lang.Object
-
- org.grails.io.support.AbstractFileResolvingResource
-
- org.grails.io.support.UrlResource
-
- All Implemented Interfaces:
Resource
public class UrlResource extends AbstractFileResolvingResource
Resource implementation forjava.net.URLlocators. Obviously supports resolution as URL, and also as File in case of the "file:" protocol.- Since:
- 28.12.2003
- See Also:
URL
-
-
Constructor Summary
Constructors Constructor Description UrlResource(java.lang.String path)Create a new UrlResource.UrlResource(java.net.URI uri)Create a new UrlResource.UrlResource(java.net.URL url)Create a new UrlResource.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ResourcecreateRelative(java.lang.String relativePath)This implementation creates a UrlResource, applying the given path relative to the path of the underlying URL of this resource descriptor.booleanequals(java.lang.Object obj)This implementation compares the underlying URL references.java.lang.StringgetDescription()This implementation returns a description that includes the URL.java.io.FilegetFile()This implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.java.lang.StringgetFilename()This implementation returns the name of the file that this URL refers to.java.io.InputStreamgetInputStream()This implementation opens an InputStream for the given URL.java.net.URIgetURI()This implementation returns the underlying URI directly, if possible.java.net.URLgetURL()This implementation returns the underlying URL reference.inthashCode()This implementation returns the hash code of the underlying URL reference.java.lang.StringtoString()-
Methods inherited from class org.grails.io.support.AbstractFileResolvingResource
contentLength, exists, getFile, getFileForLastModifiedCheck, isReadable, lastModified
-
-
-
-
Constructor Detail
-
UrlResource
public UrlResource(java.net.URL url)
Create a new UrlResource.- Parameters:
url- a URL
-
UrlResource
public UrlResource(java.net.URI uri) throws java.net.MalformedURLExceptionCreate a new UrlResource.- Parameters:
uri- a URI- Throws:
java.net.MalformedURLException- if the given URL path is not valid
-
UrlResource
public UrlResource(java.lang.String path) throws java.net.MalformedURLExceptionCreate a new UrlResource.- Parameters:
path- a URL path- Throws:
java.net.MalformedURLException- if the given URL path is not valid
-
-
Method Detail
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOExceptionThis implementation opens an InputStream for the given URL. It sets the "UseCaches" flag tofalse, mainly to avoid jar file locking on Windows.- Returns:
- The input stream
- Throws:
java.io.IOException- See Also:
URL.openConnection(),URLConnection.setUseCaches(boolean),URLConnection.getInputStream()
-
getURL
public java.net.URL getURL() throws java.io.IOExceptionThis implementation returns the underlying URL reference.- Throws:
java.io.IOException- if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor
-
getURI
public java.net.URI getURI() throws java.io.IOExceptionThis implementation returns the underlying URI directly, if possible.- Throws:
java.io.IOException- if the resource cannot be resolved as URI, i.e. if the resource is not available as descriptor
-
getFile
public java.io.File getFile() throws java.io.IOExceptionThis implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.- Specified by:
getFilein interfaceResource- Overrides:
getFilein classAbstractFileResolvingResource- Throws:
java.io.IOException- if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system
-
createRelative
public Resource createRelative(java.lang.String relativePath)
This implementation creates a UrlResource, applying the given path relative to the path of the underlying URL of this resource descriptor.- Parameters:
relativePath- The relative path- Returns:
- The new resource
- See Also:
URL(java.net.URL, String)
-
getFilename
public java.lang.String getFilename()
This implementation returns the name of the file that this URL refers to.- See Also:
URL.getFile(),File.getName()
-
getDescription
public java.lang.String getDescription()
This implementation returns a description that includes the URL.- See Also:
Object.toString()
-
equals
public boolean equals(java.lang.Object obj)
This implementation compares the underlying URL references.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
This implementation returns the hash code of the underlying URL reference.- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-