Class LocalUriFetcher<T>
- java.lang.Object
-
- com.bumptech.glide.load.data.LocalUriFetcher<T>
-
- Type Parameters:
T- The type of data that will obtained for the given uri (For example,InputStreamorParcelFileDescriptor.
- All Implemented Interfaces:
DataFetcher<T>
- Direct Known Subclasses:
AssetFileDescriptorLocalUriFetcher,FileDescriptorLocalUriFetcher,StreamLocalUriFetcher
public abstract class LocalUriFetcher<T> extends java.lang.Object implements DataFetcher<T>
A DataFetcher that uses anContentResolverto load data from aUripointing to a local resource.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.bumptech.glide.load.data.DataFetcher
DataFetcher.DataCallback<T>
-
-
Constructor Summary
Constructors Constructor Description LocalUriFetcher(android.content.ContentResolver contentResolver, android.net.Uri uri)Opens an input stream for a uri pointing to a local asset.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete 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.protected abstract voidclose(T data)Closes the concrete data type if necessary.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.protected abstract TloadResource(android.net.Uri uri, android.content.ContentResolver contentResolver)Returns a concrete data type from the givenUriusing the givenContentResolver.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.bumptech.glide.load.data.DataFetcher
getDataClass
-
-
-
-
Constructor Detail
-
LocalUriFetcher
public LocalUriFetcher(android.content.ContentResolver contentResolver, android.net.Uri uri)Opens an input stream for a uri pointing to a local asset. Only certain uris are supported- Parameters:
contentResolver- AnyContentResolver.uri- A Uri pointing to a local asset. This load will fail if the uri isn't openable byContentResolver.openInputStream(android.net.Uri)- See Also:
ContentResolver.openInputStream(android.net.Uri)
-
-
Method Detail
-
loadData
public final void loadData(@NonNull Priority priority, @NonNull DataFetcher.DataCallback<? super T> callback)Description copied from interface:DataFetcherFetch 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.
- Specified by:
loadDatain interfaceDataFetcher<T>- 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
public void cleanup()
Description copied from interface:DataFetcherCleanup or recycle any resources used by this data fetcher. This method will be called in a finally block after the data provided byDataFetcher.loadData(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.
- Specified by:
cleanupin interfaceDataFetcher<T>
-
cancel
public void cancel()
Description copied from interface:DataFetcherA 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:
cancelin interfaceDataFetcher<T>
-
getDataSource
@NonNull public DataSource getDataSource()
Description copied from interface:DataFetcherReturns theDataSourcethis fetcher will return data from.- Specified by:
getDataSourcein interfaceDataFetcher<T>
-
loadResource
protected abstract T loadResource(android.net.Uri uri, android.content.ContentResolver contentResolver) throws java.io.FileNotFoundException
Returns a concrete data type from the givenUriusing the givenContentResolver.- Throws:
java.io.FileNotFoundException
-
close
protected abstract void close(T data) throws java.io.IOException
Closes the concrete data type if necessary.Note - We can't rely on the closeable interface because it was added after our min API level. See issue #157.
- Parameters:
data- The data to close.- Throws:
java.io.IOException
-
-