Interface DataFetcher<T>
-
- Type Parameters:
T- The type of data to be loaded (InputStream, byte[], File etc).
- All Known Implementing Classes:
AssetFileDescriptorLocalUriFetcher,AssetPathFetcher,FileDescriptorAssetPathFetcher,FileDescriptorLocalUriFetcher,HttpUrlFetcher,LocalUriFetcher,StreamAssetPathFetcher,StreamLocalUriFetcher,ThumbFetcher
public interface DataFetcher<T>Lazily retrieves data that can be used to load a resource.A new instance is created per resource load by
ModelLoader.loadData(com.bumptech.glide.Priority, com.bumptech.glide.load.data.DataFetcher.DataCallback)may or may not be called for any given load depending on whether or not the corresponding resource is cached. Cancel also may or may not be called. IfloadData(com.bumptech.glide.Priority, com.bumptech.glide.load.data.DataFetcher.DataCallback)} is called, then socleanup()will be called.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceDataFetcher.DataCallback<T>Callback that must be called when data has been loaded and is available, or when the load fails.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcancel()A method that will be called when a load is no longer relevant and has been cancelled.voidcleanup()Cleanup or recycle any resources used by this data fetcher.java.lang.Class<T>getDataClass()Returns the class of the data this fetcher will attempt to obtain.DataSourcegetDataSource()Returns theDataSourcethis fetcher will return data from.voidloadData(Priority priority, DataFetcher.DataCallback<? super T> callback)Fetch data from which a resource can be decoded.
-
-
-
Method Detail
-
loadData
void loadData(@NonNull Priority priority, @NonNull DataFetcher.DataCallback<? super T> callback)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 (or move the work to another thread) since this method will be called from a thread in a
ExecutorServicethat may have more than one background thread. You MUST use theDataFetcher.DataCallbackonce the request is complete.You are free to move the fetch work to another thread and call the callback from there.
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.
- Parameters:
priority- The priority with which the request should be completed.callback- The callback to use when the request is complete- See Also:
where the data retuned will be cleaned up
-
cleanup
void cleanup()
Cleanup or recycle any resources used by this data fetcher. This method will be called in a finally block after the data provided byloadData(com.bumptech.glide.Priority, com.bumptech.glide.load.data.DataFetcher.DataCallback)has been decoded by theResourceDecoder.Note - this method will be run on a background thread so blocking I/O is safe.
-
cancel
void cancel()
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.
-
getDataClass
@NonNull java.lang.Class<T> getDataClass()
Returns the class of the data this fetcher will attempt to obtain.
-
getDataSource
@NonNull DataSource getDataSource()
Returns theDataSourcethis fetcher will return data from.
-
-