use of io.reactivex.ObservableOperator in project navajo by Dexels.
the class StreamDocument method createBinary.
public static ObservableOperator<Binary, byte[]> createBinary() {
return new ObservableOperator<Binary, byte[]>() {
@Override
public Observer<? super byte[]> apply(Observer<? super Binary> out) throws Exception {
Binary result = new Binary();
result.startBinaryPush();
return new Observer<byte[]>() {
@Override
public void onComplete() {
try {
result.finishPushContent();
} catch (IOException e) {
e.printStackTrace();
out.onError(e);
return;
}
out.onNext(result);
out.onComplete();
}
@Override
public void onError(Throwable e) {
out.onError(e);
}
@Override
public void onNext(byte[] b) {
result.pushContent(b);
}
@Override
public void onSubscribe(Disposable d) {
out.onSubscribe(new Disposable() {
private boolean disposed = false;
@Override
public void dispose() {
disposed = true;
}
@Override
public boolean isDisposed() {
return disposed;
}
});
}
};
}
};
}
use of io.reactivex.ObservableOperator in project navajo by Dexels.
the class CSV method rows.
public static ObservableOperator<Row, String> rows(final String columnSeparator) {
return new ObservableOperator<Row, String>() {
@Override
public Observer<? super String> apply(Observer<? super Row> child) throws Exception {
return new Observer<String>() {
final AtomicInteger counter = new AtomicInteger();
final List<String> columns = new ArrayList<>();
private Disposable disposable;
@Override
public void onComplete() {
child.onComplete();
}
@Override
public void onError(Throwable e) {
logger.error("Error: ", e);
child.onError(e);
}
@Override
public void onNext(String line) {
int current = counter.getAndIncrement();
if (current == 0) {
columns.addAll(CSV.columnNames(columnSeparator, line));
} else {
Row r = CSV.parseLine(columnSeparator, columns, line);
if (!disposable.isDisposed()) {
child.onNext(r);
}
}
}
@Override
public void onSubscribe(Disposable d) {
disposable = d;
}
};
}
};
}
Aggregations