public class OkHttpStreamFetcher extends Object implements DataFetcher<InputStream>, Callback
InputStream
using the okhttp library.DataFetcher.DataCallback<T>
Constructor and Description |
---|
OkHttpStreamFetcher(Call.Factory client,
GlideUrl url) |
Modifier and Type | Method and 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.
|
Class<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 InputStream> callback)
Fetch data from which a resource can be decoded.
|
void |
onFailure(Call call,
IOException e) |
void |
onResponse(Call call,
Response response) |
public OkHttpStreamFetcher(Call.Factory client, GlideUrl url)
public void loadData(@NonNull Priority priority, @NonNull DataFetcher.DataCallback<? super InputStream> callback)
DataFetcher
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.
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.
loadData
in interface DataFetcher<InputStream>
priority
- The priority with which the request should be completed.callback
- The callback to use when the request is completewhere the data retuned will be cleaned up
public void onFailure(@NonNull Call call, @NonNull IOException e)
public void onResponse(@NonNull Call call, @NonNull Response response)
onResponse
in interface Callback
public void cleanup()
DataFetcher
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.
cleanup
in interface DataFetcher<InputStream>
public void cancel()
DataFetcher
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.
cancel
in interface DataFetcher<InputStream>
@NonNull public Class<InputStream> getDataClass()
DataFetcher
getDataClass
in interface DataFetcher<InputStream>
@NonNull public DataSource getDataSource()
DataFetcher
DataSource
this fetcher will return data from.getDataSource
in interface DataFetcher<InputStream>