com.bumptech.glide.load.data
Class AssetPathFetcher<T>

java.lang.Object
  extended by com.bumptech.glide.load.data.AssetPathFetcher<T>
Type Parameters:
T - The type of data obtained from the asset path (InputStream, FileDescriptor etc).
All Implemented Interfaces:
DataFetcher<T>
Direct Known Subclasses:
FileDescriptorAssetPathFetcher, StreamAssetPathFetcher

public abstract class AssetPathFetcher<T>
extends Object
implements DataFetcher<T>

An abstract class for obtaining data for an asset path using an AssetManager.


Constructor Summary
AssetPathFetcher(AssetManager assetManager, String assetPath)
           
 
Method Summary
 void cancel()
          A method that will be called when a load is no longer relevant and has been cancelled.
 void cleanup()
          Cleanup or recycle any resources used by this data fetcher.
protected abstract  void close(T data)
          Closes the concrete data type if necessary.
 String getId()
          Returns a string uniquely identifying the data that this fetcher will fetch including the specific size.
 T loadData(Priority priority)
          Asynchronously fetch data from which a resource can be decoded.
protected abstract  T loadResource(AssetManager assetManager, String path)
          Opens the given asset path with the given AssetManager and returns the conrete data type returned by the AssetManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AssetPathFetcher

public AssetPathFetcher(AssetManager assetManager,
                        String assetPath)
Method Detail

loadData

public T loadData(Priority priority)
           throws Exception
Description copied from interface: DataFetcher
Asynchronously fetch data from which a resource can be decoded. This will always be called on background thread so it is safe to perform long running tasks here. Any third party libraries called must be thread safe since this method will be called from a thread in a ExecutorService that may have more than one background thread. This method will only be called when the corresponding resource is not in the cache.

Note - this method will be run on a background thread so blocking I/O is safe.

Specified by:
loadData in interface DataFetcher<T>
Parameters:
priority - The priority with which the request should be completed.
Throws:
Exception
See Also:
where the data retuned will be cleaned up

cleanup

public void cleanup()
Description copied from interface: DataFetcher
Cleanup or recycle any resources used by this data fetcher. This method will be called in a finally block after the data returned by DataFetcher.loadData(Priority) has been decoded by the ResourceDecoder.

Note - this method will be run on a background thread so blocking I/O is safe.

Specified by:
cleanup in interface DataFetcher<T>

getId

public String getId()
Description copied from interface: DataFetcher
Returns a string uniquely identifying the data that this fetcher will fetch including the specific size.

A hash of the bytes of the data that will be fetched is the ideal id but since that is in many cases impractical, urls, file paths, and uris are normally sufficient.

Note - this method will be run on the main thread so it should not perform blocking operations and should finish quickly.

Specified by:
getId in interface DataFetcher<T>

cancel

public void cancel()
Description copied from interface: DataFetcher
A method that will be called when a load is no longer relevant and has been cancelled. This method does not need to guarantee that any in process loads do not finish. It also may be called before a load starts or after it finishes.

The best way to use this method is to cancel any loads that have not yet started, but allow those that are in process to finish since its we typically will want to display the same resource in a different view in the near future.

Note - this method will be run on the main thread so it should not perform blocking operations and should finish quickly.

Specified by:
cancel in interface DataFetcher<T>

loadResource

protected abstract T loadResource(AssetManager assetManager,
                                  String path)
                           throws IOException
Opens the given asset path with the given AssetManager and returns the conrete data type returned by the AssetManager.

Parameters:
assetManager - An AssetManager to use to open the given path.
path - A string path pointing to a resource in assets to open.
Throws:
IOException

close

protected abstract void close(T data)
                       throws IOException
Closes the concrete data type if necessary.

Parameters:
data - The data to close.
Throws:
IOException