use of com.dexels.navajo.document.stream.io.BaseFlowableOperator in project navajo by Dexels.
the class JSON method parseFlowable.
public static FlowableOperator<Flowable<JSONEvent>, byte[]> parseFlowable(int queueSize) {
return new BaseFlowableOperator<Flowable<JSONEvent>, byte[]>(queueSize) {
@Override
public Subscriber<? super byte[]> apply(Subscriber<? super Flowable<JSONEvent>> child) throws Exception {
return new Subscriber<byte[]>() {
JSONToIterable parser = new JSONToIterable(new JsonFactory());
@Override
public void onComplete() {
Flowable<JSONEvent> fromIterable = Flowable.fromIterable(parser.endOfInput());
queue.offer(fromIterable);
done = true;
drain(child);
}
@Override
public void onError(Throwable t) {
error = t;
done = true;
drain(child);
}
@Override
public void onNext(byte[] data) {
Flowable<JSONEvent> fromIterable;
try {
fromIterable = Flowable.fromIterable(parser.feed(data));
queue.offer(fromIterable);
drain(child);
} catch (IOException e) {
child.onError(e);
return;
}
}
@Override
public void onSubscribe(Subscription s) {
subscription = s;
child.onSubscribe(new Subscription() {
@Override
public void request(long n) {
BackpressureHelper.add(requested, n);
drain(child);
}
@Override
public void cancel() {
cancelled = true;
s.cancel();
}
});
s.request(1);
}
};
}
};
}
Aggregations