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, InputStream or ParcelFileDescriptor.
All Implemented Interfaces:
DataFetcher<T>
Direct Known Subclasses:
AssetFileDescriptorLocalUriFetcher, FileDescriptorLocalUriFetcher, StreamLocalUriFetcher

public abstract class LocalUriFetcher<T> extends Object implements DataFetcher<T>
A DataFetcher that uses an ContentResolver to load data from a Uri pointing to a local resource.
  • Constructor Details

  • Method Details

    • loadData

      public final void loadData(@NonNull Priority priority, @NonNull DataFetcher.DataCallback<? super T> callback)
      Description copied from interface: DataFetcher
      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 ExecutorService that may have more than one background thread. You MUST use the DataFetcher.DataCallback once 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:
      loadData in interface DataFetcher<T>
      Parameters:
      priority - The priority with which the request should be completed.
      callback - The callback to use when the request is complete
      See Also:
    • 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 provided by DataFetcher.loadData(com.bumptech.glide.Priority, com.bumptech.glide.load.data.DataFetcher.DataCallback) 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>
    • 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>
    • getDataSource

      @NonNull public DataSource getDataSource()
      Description copied from interface: DataFetcher
      Returns the DataSource this fetcher will return data from.
      Specified by:
      getDataSource in interface DataFetcher<T>
    • loadResource

      protected abstract T loadResource(Uri uri, ContentResolver contentResolver) throws FileNotFoundException
      Returns a concrete data type from the given Uri using the given ContentResolver.
      Throws:
      FileNotFoundException
    • close

      protected abstract void close(T data) throws 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:
      IOException