putData
Class: matlab.net.http.io.ContentConsumer
Namespace: matlab.net.http.io
Process or save next buffer of data for ContentConsumer
Syntax
[size,stop] = putData(consumer,data)
Description
[
provides a buffer of size
,stop
] = putData(consumer
,data
)data
read from the server to the
consumer
.
MATLAB® calls putData
. Subclass consumers can override this
method to receive streamed data. Your consumer should return the length of data that it
actually processed in size
, and a true/false indication in
stop
to specify whether it wants to receive further data from
this message.
When MATLAB calls putData
with an empty data
argument, it means that the message or message part in the case of a multipart message
has ended.
If you create a subclass of a consumer that implements this method, your
putData
method can call its superclass putData
to
take advantage of any conversions or processing that the superclass implements.
MATLAB limits the size of data
buffers to the
bufsize
value returned by the start
method or an internal buffer size if bufsize
is
[]
. Also, if the server sends a chunk-encoded message, then a given
call to putData
never provides more than one chunk. This allows the
consumer to obtain slowly arriving chunks in a timely manner even if
bufsize
is much larger than the chunk size.
Default behavior of putData()
in this base class:
Subclass consumers have the option of storing their possibly converted content
directly in Response.Body.Data
, either incrementally or all at
once, or disposing of it in some other way. The subclass consumer does not need to call
this putData
method to store data. As a convenience, consumers that
want to store content incrementally in Response.Body.Data
can call
this method to do so. This method appends data
to
Response.Body.Data
using the AppendFcn
,
attempting to do so efficiently by incrementally allocating capacity. The actual length
of stored data is maintained in the CurrentLength
property, which
can be smaller than the actual length of Response.Body.Data
. At the
end of the transfer (for example, when putData(consumer,[])
or
putData(consumer,uint8.empty)
is called,
Response.Body.Data
is truncated to
CurrentLength
. You can define your own
AppendFcn
to implement an alternative append method.
By default this method always returns size
equal to the
numel(data)
and stop
equal to
false
.
If you intend to use this method to store data and you know the maximum length of data
to be stored, then you should set Response.Body.Data
to a vector of
the desired size filled with default values (for example, zeros), before calling this
method for the first time. This method starts storing data at the beginning of your data
area and then truncates it to the length of data at the end of the message, maintaining
the length of data stored in CurrentLength
.
Consumers that call this method in this base class to store data incrementally can
provide data
of any type that supports horzcat
or vertcat
, including structures and cell arrays. If you provide a
cell array, the existing Data is converted to a cell array if it is not already, and
elements of the cell array are inserted into the existing cell array at the linear index
beginning at CurrentLength
+1.
If you call this method in ContentConsumer
to store data, then you
should let this method manage Response.Body.Data
or
CurrentLength
and not modify them directly.
ContentConsumers
that call this method in their superclass should be
prepared to do any cleanup, such as closing windows or deleting temporary files, if the
superclass throws an exception.
Input Arguments
Output Arguments
Attributes
Access | public |
Version History
Introduced in R2018a