initialize
Class: matlab.net.http.io.ContentConsumer
Namespace: matlab.net.http.io
Prepare consumer for new HTTP payload
Syntax
OK = initialize(consumer)
Description
prepares a OK
= initialize(consumer
)ContentConsumer
for use with a new HTTP payload.
MATLAB® calls initialize
after receipt of the header of a
ResponseMessage
that might contain a payload, to prepare the consumer
for that payload. It is not invoked for messages not expected to contain a payload, such
as those with an explicit Content-Length of 0, or in error cases where a complete header
was not received.
The delegateTo
method in a delegate consumer also calls initialize
.
If you subclass a ContentConsumer
, then you should at least check the
ContentType property to verify that the response is of the type you are
prepared to handle. You can override this method to, for example:
Initialize your own properties
Determine if you want to process the payload
Process a payload that has a
Response.StatusCode
other thanOK
It is up to you whether to perform any subsequent initializations in this method or
delay them until the start
method.
Even if initialize
is called, MATLAB might not call the consumer's start
method if the message has no payload.
The default implementation returns true
if the
Response.StatusCode
is OK
and
false
otherwise. Subclasses that override this method should
invoke this superclass method first and check the return value, unless they want to
process messages with a status other than OK
. Subclasses that invoke
putData
in this class must call this method.
Consumer subclasses should be prepared to be reused for subsequent messages.
MATLAB calls initialize
before each message and then
start
for each message that has a nonempty payload. Once
MATLAB calls start
, it does not call initialize
until the message has ended, an exception was thrown, or an interrupt occurred during
message processing. All these cases are indicated by a call to
putData(uint8.empty)
.
Input Arguments
Output Arguments
Attributes
Access | protected |
Version History
Introduced in R2018a
See Also
matlab.net.http.RequestMessage
| matlab.net.http.StatusCode
| start
| putData
| delegateTo
| CurrentLength | Response