-
Notifications
You must be signed in to change notification settings - Fork 16
NetworkInterpreter
NetworkInterpreter is an interface whose implementations are supposed to interpret the input stream and call either the success or failure methods.
It has two methods
-
Response interpretResponseStream(int requestId, NetworkInterceptor.TimeInfo timeInfo, Request request, Response response) throws IOException
: This is used to interpret the input stream received from the responsebody, and give back an response object. -
void interpretError(int requestId, NetworkInterceptor.TimeInfo timeInfo, Request request, IOException e)
: This is used to interpret the error received.
The library provides a default implementation of NetworkInterpreter interface, DefaultInterpreter. This is where the important param such as the request size, request url, response size, response time, status code are noted and bubbled to the NetworkEventReporter which is used to report these events further.
There are two type of response, one with Content-Length, and other which does not have the Content-Length in their header.
-
If the response header contains the Content-Length, we directly notify the event reporter that response has been received.
-
In case if the response header does not contain the Content-Length, the CountingInputStream is used to read its bytes, and then the reporting is done.
The CountingInputStream uses a DefaultResponseHandler which is used to give a callback as soon as the response input stream is read with the number of bytes read as parameter. As soon as callback is received, we directly notify the event reporter that response has been received.