Skip to content

Subsection for Upload Post API

Sheng Liang edited this page May 17, 2018 · 1 revision

Upload/Post API (Streaming)

The interface of streaming resource is similar to the asynchronous resources with a callback parameter that’s used to return the result.

T

@Override
public void create(@UnstructuredDataReactiveReaderParam UnstructuredDataReactiveReader reader, Callback<CreateResponse> callback) {
  reader.getEntityStream().setReader(new GreetingUnstructuredDataReader(responseCallback));
}

Create Response

The standard CreateResponse represents the response of the uploading.

Reading Unstructured Data

Streaming requires the data to be read/written in continuous chunks manner. Simple bytes array or InputStream won’t do the job. Rest.li adopt the EntityStream interface. Refer to their documentation for more details.

ByteString is essentially Rest.li’s immutable bytes array implementation and is used here to represent a single chunk. Asynchronously, a number of chunks (determined by the data EntityStream) will be received by this Reader at a later time.

Reading Unstructured Data w. R2 Reader

Rest.li’s R2 layer has its own similar EntityStream implementation. If a writer is already provided, it can be easily converted to Rest.Li Writer using EntityStreamAdapters util.

Writer dataWriter = new ResumeDataWriter(id);
com.linkedin.entitystream.Writer<ByteString> dataPublisher = EntityStreamAdapters.toGenericWriterx(dataWriter);
Clone this wiki locally