Class HttpUrlFetcher

  • All Implemented Interfaces:
    DataFetcher<java.io.InputStream>

    public class HttpUrlFetcher
    extends java.lang.Object
    implements DataFetcher<java.io.InputStream>
    A DataFetcher that retrieves an InputStream for a Url.
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpUrlFetcher​(GlideUrl glideUrl, int timeout)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      java.lang.Class<java.io.InputStream> getDataClass()
      Returns the class of the data this fetcher will attempt to obtain.
      DataSource getDataSource()
      Returns the DataSource this fetcher will return data from.
      void loadData​(Priority priority, DataFetcher.DataCallback<? super java.io.InputStream> callback)
      Fetch data from which a resource can be decoded.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HttpUrlFetcher

        public HttpUrlFetcher​(GlideUrl glideUrl,
                              int timeout)
    • Method Detail

      • loadData

        public void loadData​(@NonNull
                             Priority priority,
                             @NonNull
                             DataFetcher.DataCallback<? super java.io.InputStream> 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<java.io.InputStream>
        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
      • 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<java.io.InputStream>
      • getDataClass

        @NonNull
        public java.lang.Class<java.io.InputStream> getDataClass()
        Description copied from interface: DataFetcher
        Returns the class of the data this fetcher will attempt to obtain.
        Specified by:
        getDataClass in interface DataFetcher<java.io.InputStream>