java - Efficient way to transform ByteBuffer stream into lines in Rx -
i want transform observable<bytebuffer>
lines (observable<string>
) splitting line ending character. if have functions such tostring
, concat
, splitbyline
, must able following:
observable<bytebuffer> o = ...; o.map(tostring).reduce(concat).flatmap(splitbyline);
this algorithm, however, needs scan whole bytes first , store them in memory before emit first line of deserialized string. how emit new line each time line ending appears in bytes incrementally?
i found rxjava-string. provides rx operators handle stream of chunked byte arrays , strings. api document found here.
the question can achieved following:
observable<byte[]> o = ...; charset charset = charset.forname("utf-8"); // stringobservable have no operators bytebuffer yet stringobservable.byline(stringobservable.decode(o, charset));
Comments
Post a Comment