public abstract class

NetworkFetchProducer

extends Object
implements Producer<T>
java.lang.Object
   ↳ com.facebook.imagepipeline.producers.NetworkFetchProducer<RS extends com.facebook.imagepipeline.producers.NfpRequestState>

Class Overview

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.

Summary

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
From class java.lang.Object
From interface com.facebook.imagepipeline.producers.Producer

Constants

public static final String INTERMEDIATE_RESULT_PRODUCER_EVENT

Constant Value: "intermediate_result"

Public Constructors

public NetworkFetchProducer (PooledByteBufferFactory pooledByteBufferFactory, ByteArrayPool byteArrayPool)

Public Methods

public void produceResults (Consumer<CloseableReference<PooledByteBuffer>> consumer, ProducerContext context)

Protected Methods

protected Map<String, String> buildExtraMapForFinalResult (int byteSize, RS requestState)

Override this to provide a map containing extra parameters to pass to the listeners.

Returns
  • An immutable map of the parameters. Attempts to modify this map afterwards will result in an exception being thrown.

protected abstract void fetchImage (RS requestState)

Subclasses should override this method to actually call their network stack.

It is strongly recommended that this method be asynchronous.

protected String getProducerName ()

Returns the name of the producer.

This name is passed to the ProducerListeners.

protected void handleFinalResult (PooledByteBufferOutputStream pooledOutputStream, RS requestState)

protected abstract RS newRequestState (Consumer<CloseableReference<PooledByteBuffer>> consumer, ProducerContext context)

Returns an instance of the NfpRequestState-derived object used to store state.

protected void onCancellation (RS requestState, Map<String, String> extraMap)

Called upon a cancellation of the request.

Parameters
requestState Request-specific data.
extraMap An immutable map of the parameters. Attempts to modify this map afterwards will result in an exception being thrown.

protected void onFailure (RS requestState, Throwable e, Map<String, String> extraMap)

Called upon a failure in the network stack.

Parameters
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.

protected void processResult (RS requestState, InputStream responseData, int responseContentLength, boolean propagateIntermediateResults)

Throws
IOException