Spring for Android

org.springframework.core.io
Class AssetResource

java.lang.Object
  extended by org.springframework.core.io.AbstractResource
      extended by org.springframework.core.io.AssetResource
All Implemented Interfaces:
InputStreamSource, Resource

public class AssetResource
extends AbstractResource

Resource implementation for Android asset resources.

Since:
1.0
Author:
Roy Clarkson

Constructor Summary
AssetResource(android.content.res.AssetManager assetManager, java.lang.String fileName)
          Create a new AssetResource.
 
Method Summary
 long contentLength()
          This implementation checks the length of the underlying AssetFileDescriptor, if available.
 boolean equals(java.lang.Object obj)
          This implementation compares the file names of the resources.
 boolean exists()
          This implementation returns whether the underlying asset exists.
 java.lang.String getDescription()
          Return a description for this resource, to be used for error output when working with the resource.
 java.io.InputStream getInputStream()
          Return an InputStream.
 int hashCode()
          This implementation returns the hash code of the file name.
 
Methods inherited from class org.springframework.core.io.AbstractResource
createRelative, getFile, getFileForLastModifiedCheck, getFilename, getURI, getURL, isOpen, isReadable, lastModified, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AssetResource

public AssetResource(android.content.res.AssetManager assetManager,
                     java.lang.String fileName)
Create a new AssetResource.

The Android AssetManager will be used for loading the resource.

Parameters:
fileName - the name of the asset to open.
See Also:
AssetManager.open(String)
Method Detail

exists

public boolean exists()
This implementation returns whether the underlying asset exists.

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

contentLength

public long contentLength()
                   throws java.io.IOException
This implementation checks the length of the underlying AssetFileDescriptor, if available.

Specified by:
contentLength in interface Resource
Overrides:
contentLength in class AbstractResource
Throws:
java.io.IOException - if the resource cannot be resolved (in the file system or as some other known physical resource type)
See Also:
AssetFileDescriptor.getLength()

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()

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.

This requirement is particularly important when you consider an API such as JavaMail, which needs to be able to read the stream multiple times when creating mail attachments. For such a use case, it is required that each getInputStream() call returns a fresh stream.

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

equals

public boolean equals(java.lang.Object obj)
This implementation compares the file names of the resources.

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

hashCode

public int hashCode()
This implementation returns the hash code of the file name.

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

Spring for Android