org.springframework.core.io
Class FileSystemResource

java.lang.Object
  extended byorg.springframework.core.io.AbstractResource
      extended byorg.springframework.core.io.FileSystemResource
All Implemented Interfaces:
InputStreamSource, Resource

public class FileSystemResource
extends AbstractResource

Resource implementation for java.io.File handles. Obviously supports resolution as File, and also as URL.

Since:
28.12.2003
Author:
Juergen Hoeller
See Also:
File

Field Summary
 
Fields inherited from class org.springframework.core.io.AbstractResource
URL_PROTOCOL_FILE
 
Constructor Summary
FileSystemResource(java.io.File file)
          Create a new FileSystemResource.
FileSystemResource(java.lang.String path)
          Create a new FileSystemResource.
 
Method Summary
 boolean exists()
          This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.
 java.lang.String getDescription()
          Return a description for this resource, to be used for error output when working with the resource.
 java.io.File getFile()
          This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.
 java.io.InputStream getInputStream()
          Return an InputStream.
 java.net.URL getURL()
          This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.
 
Methods inherited from class org.springframework.core.io.AbstractResource
equals, hashCode, isOpen, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileSystemResource

public FileSystemResource(java.io.File file)
Create a new FileSystemResource.

Parameters:
file - a File handle

FileSystemResource

public FileSystemResource(java.lang.String path)
Create a new FileSystemResource.

Parameters:
path - a file path
Method Detail

exists

public boolean exists()
Description copied from class: AbstractResource
This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened. This will cover both directories and content resources.

Specified by:
exists in interface Resource
Overrides:
exists in class AbstractResource

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Description copied from interface: InputStreamSource
Return an InputStream. It is expected that each call creates a fresh stream.

Throws:
java.io.IOException - if the stream could not be opened

getURL

public java.net.URL getURL()
                    throws java.io.IOException
Description copied from class: AbstractResource
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.

Specified by:
getURL in interface Resource
Overrides:
getURL in class AbstractResource
Throws:
java.io.IOException

getFile

public java.io.File getFile()
Description copied from class: AbstractResource
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.

Specified by:
getFile in interface Resource
Overrides:
getFile in class AbstractResource

getDescription

public java.lang.String getDescription()
Description copied from interface: Resource
Return a description for this resource, to be used for error output when working with the resource.

Implementations are also encouraged to return this value from their toString method.

See Also:
Object.toString()


Copyright (C) 2003-2004 The Spring Framework Project.