Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.core.io
Class UrlResource

    java.lang.Object
      org.springframework.core.io.AbstractResource
          org.springframework.core.io.UrlResource

All Implemented Interfaces:
  InputStreamSource, Resource

    public class UrlResource

extends AbstractResource

`Resource` implementation for `java.net.URL` locators. Obviously supports resolution as URL, and also as File in case of the "file:" protocol.

Since:
  28.12.2003
Author:
  Juergen Hoeller
See Also:
  `URL`

Constructor Summary
`UrlResource(String path)` Create a new UrlResource.
`UrlResource(URL url)` Create a new UrlResource.

Method Summary
`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, 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.
`URL` | `getURL()` This implementation returns the underlying URL reference.
`int` | `hashCode()` This implementation returns the hash code of the underlying URL reference.

Methods inherited from class org.springframework.core.io.AbstractResource
`exists, isOpen, toString`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### UrlResource

    public UrlResource(URL url)

  Create a new UrlResource.

  Parameters:
    `url` - a URL

### UrlResource

    public UrlResource(String path)
                throws MalformedURLException

  Create a new UrlResource.

  Parameters:
    `path` - a URL path
  Throws:
    `MalformedURLException` - if the given URL path is not valid

Method Detail

### getInputStream

    public InputStream getInputStream()
                               throws IOException

  This implementation opens an InputStream for the given URL. It sets the "UseCaches" flag to `false`, mainly to avoid jar file locking on Windows.

  Throws:
    `IOException` - if the stream could not be opened
  See Also:
    `URL.openConnection()`, `URLConnection.setUseCaches(boolean)`, `URLConnection.getInputStream()`

### getURL

    public URL getURL()
               throws IOException

  This implementation returns the underlying URL reference.

  Specified by:
    `getURL` in interface `Resource`
  Overrides:
    `getURL` in class `AbstractResource`
  Throws:
    `IOException` - if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor

### getFile

    public File getFile()
                 throws IOException

  This implementation returns a File reference for the underlying URL, provided that it refers to a file in the file system.

  Specified by:
    `getFile` in interface `Resource`
  Overrides:
    `getFile` in class `AbstractResource`
  Throws:
    `IOException` - if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system
  See Also:
    `ResourceUtils.getFile(java.net.URL, String)`

### createRelative

    public Resource createRelative(String relativePath)
                            throws MalformedURLException

  This implementation creates a UrlResource, applying the given path relative to the path of the underlying URL of this resource descriptor.

  Specified by:
    `createRelative` in interface `Resource`
  Overrides:
    `createRelative` in class `AbstractResource`
  Parameters:
    `relativePath` - the relative path (relative to this resource)
  Returns:
    the resource handle for the relative resource
  Throws:
    `MalformedURLException`
  See Also:
    `URL.URL(java.net.URL, String)`

### getFilename

    public String getFilename()

  This implementation returns the name of the file that this URL refers to.

  Specified by:
    `getFilename` in interface `Resource`
  Overrides:
    `getFilename` in class `AbstractResource`
  See Also:
    `URL.getFile()`, `File.getName()`

### getDescription

    public String getDescription()

  This implementation returns a description that includes the URL.

  Specified by:
    `getDescription` in interface `Resource`
  Specified by:
    `getDescription` in class `AbstractResource`
  See Also:
    `Resource.getDescription()`, `AbstractResource.toString()`, `AbstractResource.equals(Object)`, `AbstractResource.hashCode()`

### equals

    public boolean equals(Object obj)

  This implementation compares the underlying URL references.

  Overrides:
    `equals` in class `AbstractResource`
  See Also:
    `AbstractResource.getDescription()`

### hashCode

    public int hashCode()

  This implementation returns the hash code of the underlying URL reference.

  Overrides:
    `hashCode` in class `AbstractResource`
  See Also:
    `AbstractResource.getDescription()`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2007 The Spring Framework.