问题
Could you please explain Square's Retrofit response parsing logic. I'm interested in case when we should receive & parse a big json (>100Kb) - will Retrofit wait while all content will be received from server and only than parse it, or it will start to parse it immediately while getting stream data? My goal is to speedup response processing.
Are there any options about it available to configure?
回答1:
As soon as the HTTP client parses the headers, the InputStream
will be handed back to Retrofit which will then hand it directly to the Converter
. This means that as the underlying converter mechanism (say, Gson) is pulling bytes they are being read (and potentially blocking) directly from the network.
Note: this is only true if logging is off (as it should be in production / release builds). When logging is turned on beyond HEADERS level, the response body has to be read in its entirety into a byte[]
in order to both log and hand the data to the converter.
来源:https://stackoverflow.com/questions/28580084/squares-retrofit-response-parsing-logic-streaming