java.lang.Object | |
↳ | com.facebook.imagepipeline.producers.NetworkFetchProducer<RS extends com.facebook.imagepipeline.producers.NfpRequestState> |
A producer to actually fetch images from the network.
Downloaded bytes are passed to the consumer as they are downloaded, but not more often than #TIME_BETWEEN_PARTIAL_RESULTS_MS.
Implementations should subclass this to make use of the network stack they are using. Use HttpURLConnectionNetworkFetchProducer as a model.
Most implementations will only need to override
newRequestState(Consumer, ProducerContext)
and fetchImage(NfpRequestState)
.
It is strongly recommended that implementations use an Executor in their fetchImage method to execute the network request on a different thread.
When the fetch from the network fails or is cancelled, the subclass is responsible for
calling onCancellation(NfpRequestState, Map)
or
onFailure(NfpRequestState, Throwable, Map)
. If these are not called, the
rest of the pipeline will not know that the image has failed to load and the application
may not behave properly.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | INTERMEDIATE_RESULT_PRODUCER_EVENT |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
NetworkFetchProducer(PooledByteBufferFactory pooledByteBufferFactory, ByteArrayPool byteArrayPool) |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void | produceResults(Consumer<CloseableReference<PooledByteBuffer>> consumer, ProducerContext context) |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Map<String, String> |
buildExtraMapForFinalResult(int byteSize, RS requestState)
Override this to provide a map containing extra parameters to pass to the listeners.
| ||||||||||
abstract void |
fetchImage(RS requestState)
Subclasses should override this method to actually call their network stack.
| ||||||||||
String |
getProducerName()
Returns the name of the producer.
| ||||||||||
void | handleFinalResult(PooledByteBufferOutputStream pooledOutputStream, RS requestState) | ||||||||||
abstract RS |
newRequestState(Consumer<CloseableReference<PooledByteBuffer>> consumer, ProducerContext context)
Returns an instance of the
NfpRequestState -derived object used to store state. | ||||||||||
void |
onCancellation(RS requestState, Map<String, String> extraMap)
Called upon a cancellation of the request.
| ||||||||||
void |
onFailure(RS requestState, Throwable e, Map<String, String> extraMap)
Called upon a failure in the network stack.
| ||||||||||
void | processResult(RS requestState, InputStream responseData, int responseContentLength, boolean propagateIntermediateResults) |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
Override this to provide a map containing extra parameters to pass to the listeners.
Subclasses should override this method to actually call their network stack.
It is strongly recommended that this method be asynchronous.
Returns the name of the producer.
This name is passed to the ProducerListener
s.
Returns an instance of the NfpRequestState
-derived object used to store state.
Called upon a cancellation of the request.
requestState | Request-specific data. |
---|---|
extraMap | An immutable map of the parameters. Attempts to modify this map afterwards will result in an exception being thrown. |
Called upon a failure in the network stack.
requestState | Request-specific data. |
---|---|
e | The exception thrown. |
extraMap | An immutable map of the parameters. Attempts to modify this map afterwards will result in an exception being thrown. |
IOException |
---|