org.opensaml.util.resource
Class FileBackedHttpResource

java.lang.Object
  extended by org.opensaml.util.resource.AbstractFilteredResource
      extended by org.opensaml.util.resource.HttpResource
          extended by org.opensaml.util.resource.FileBackedHttpResource
All Implemented Interfaces:
Resource

public class FileBackedHttpResource
extends HttpResource

A resource representing a file read from an HTTP(S) location. Every time the file is successfully read from the URL location it is written to a backing file. If the file can not be read from the URL it is read from this backing file, if available. Note, large files should not be accessed in this manner as the entire file is read into memory before being written to disk and then returned.


Constructor Summary
FileBackedHttpResource(java.lang.String resource, java.lang.String backingFile)
          Constructor.
FileBackedHttpResource(java.lang.String resource, java.lang.String backingFile, ResourceFilter resourceFilter)
          Constructor.
FileBackedHttpResource(java.lang.String resource, java.net.URI backingFile)
          Constructor.
FileBackedHttpResource(java.lang.String resource, java.net.URI backingFile, ResourceFilter resourceFilter)
          Constructor.
 
Method Summary
 boolean exists()
          Checks whether the resource exists.
 java.io.InputStream getInputStream()
          Gets the inputstream to the resource's data.
 org.joda.time.DateTime getLastModifiedTime()
          Gets the date and time the resource was last modified.
 java.lang.String getLocation()
          Gets resource location information.
protected  void saveToResourceFile(byte[] resource)
          Saves a resource to the backing file.
 
Methods inherited from class org.opensaml.util.resource.HttpResource
equals, getResource, hashCode, toString
 
Methods inherited from class org.opensaml.util.resource.AbstractFilteredResource
getResourceFilter
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileBackedHttpResource

public FileBackedHttpResource(java.lang.String resource,
                              java.lang.String backingFile)
Constructor.

Parameters:
resource - HTTP(S) URL of the resource
backingFile - filesystem location to store the resource

FileBackedHttpResource

public FileBackedHttpResource(java.lang.String resource,
                              java.net.URI backingFile)
Constructor.

Parameters:
resource - HTTP(S) URL of the resource
backingFile - file: URI location to store the resource
Since:
1.2

FileBackedHttpResource

public FileBackedHttpResource(java.lang.String resource,
                              java.lang.String backingFile,
                              ResourceFilter resourceFilter)
Constructor.

Parameters:
resource - HTTP(S) URL of the resource
backingFile - filesystem location to store the resource
resourceFilter - filter to apply to this resource

FileBackedHttpResource

public FileBackedHttpResource(java.lang.String resource,
                              java.net.URI backingFile,
                              ResourceFilter resourceFilter)
Constructor.

Parameters:
resource - HTTP(S) URL of the resource
backingFile - filesystem location to store the resource
resourceFilter - filter to apply to this resource
Since:
1.2
Method Detail

exists

public boolean exists()
               throws ResourceException
Checks whether the resource exists.

Specified by:
exists in interface Resource
Overrides:
exists in class HttpResource
Returns:
true if the resource exists, false if not
Throws:
ResourceException - thrown if there is a problem determining if the resource exists

getInputStream

public java.io.InputStream getInputStream()
                                   throws ResourceException
Gets the inputstream to the resource's data.

Specified by:
getInputStream in interface Resource
Overrides:
getInputStream in class HttpResource
Returns:
inputstream to the resource's data
Throws:
ResourceException - thrown if an input stream can not be created for the resource

getLastModifiedTime

public org.joda.time.DateTime getLastModifiedTime()
                                           throws ResourceException
Gets the date and time the resource was last modified.

Specified by:
getLastModifiedTime in interface Resource
Overrides:
getLastModifiedTime in class HttpResource
Returns:
date and time the resource was last modified
Throws:
ResourceException - thrown if the last modified time can not be determined

getLocation

public java.lang.String getLocation()
Gets resource location information. Examples might be filesystem path, URL, etc.

Specified by:
getLocation in interface Resource
Overrides:
getLocation in class HttpResource
Returns:
resource location information

saveToResourceFile

protected void saveToResourceFile(byte[] resource)
                           throws ResourceException
Saves a resource to the backing file.

Parameters:
resource - the string representation of the resource
Throws:
ResourceException - thrown if the resource backing file can not be written to


Copyright © 2006-2009 Internet2. All Rights Reserved.