本文整理汇总了Java中io.reactivex.Observable.error方法的典型用法代码示例。如果您正苦于以下问题:Java Observable.error方法的具体用法?Java Observable.error怎么用?Java Observable.error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Observable
的用法示例。
在下文中一共展示了Observable.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: searchFor
import io.reactivex.Observable; //导入方法依赖的package包/类
public Observable<List<Product>> searchFor(@NonNull String searchQueryText) {
if (searchQueryText == null) {
return Observable.error(new NullPointerException("SearchQueryText == null"));
}
if (searchQueryText.length() == 0) {
return Observable.error(new IllegalArgumentException("SearchQueryTest is blank"));
}
return backend.getAllProducts()
.delay(1000, TimeUnit.MILLISECONDS)
.flatMap(Observable::fromIterable)
.filter(product -> isProductMatchingSearchCriteria(product, searchQueryText))
.toList()
.toObservable();
}
示例2: MainPresenter
import io.reactivex.Observable; //导入方法依赖的package包/类
public MainPresenter(final AuthRepo authRepo) {
super();
this.authRepo = authRepo;
super.setupRetry(
3,
new Function<Throwable, Observable<?>>() {
@Override
public Observable<?> apply(Throwable throwable) throws Exception {
if (throwable instanceof AuthentificationException && ((AuthentificationException) throwable).statusCode == 401) {
return authRepo.authentificate().toObservable();
} else if (throwable instanceof IOException) {
return Observable.timer(3, TimeUnit.SECONDS); //wait 3 seconds before continue
}
return Observable.error(throwable);
}
});
}
示例3: test_error
import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void test_error() {
Observable<String> observable = Observable.error(new Exception("We got an Exception"));
TestObserver<String> testObserver = new TestObserver<>();
observable.subscribe(testObserver);
testObserver.assertError(Exception.class);
testObserver.assertNotComplete();
testObserver.assertErrorMessage("We got an Exception");
testObserver.assertFailure(exception -> {
return exception instanceof Exception;
});
testObserver.assertFailureAndMessage(Exception.class, "We got an Exception");
}
示例4: importSample
import io.reactivex.Observable; //导入方法依赖的package包/类
public Observable<String> importSample(Sample sample) {
try {
return importFile(sample.name, mContext.getAssets().open(sample.path), PFile.getExtension(sample.path));
} catch (IOException e) {
e.printStackTrace();
showMessage(R.string.text_import_fail);
return Observable.error(e);
}
}
示例5: parse
import io.reactivex.Observable; //导入方法依赖的package包/类
public static <T> Observable<T> parse(Response response, Class<T> clazz) {
try {
final ResponseBody responseBody = response.body();
Reader reader = responseBody.charStream();
try {
if (!response.isSuccessful()) {
ErrorResponseDto errorResponseDto = Clients
.defaultObjectMapper
.fromJson(reader, ErrorResponseDto.class);
return Observable.error(new AccessApiException(errorResponseDto, null));
}
T parsedBody = Clients
.defaultObjectMapper
.fromJson(reader, clazz);
return Observable.just(parsedBody);
} finally {
Util.closeQuietly(reader);
}
} catch (Exception e) {
return Observable.error(e);
} finally {
Util.closeQuietly(response);
}
}
示例6: getPageCoordinates
import io.reactivex.Observable; //导入方法依赖的package包/类
public Observable<Pair<Integer, RectF>> getPageCoordinates(Integer... pages) {
AyahInfoDatabaseHandler database = ayahInfoDatabaseProvider.getAyahInfoHandler();
if (database == null) {
return Observable.error(new NoSuchElementException("No AyahInfoDatabaseHandler found!"));
}
return Observable.fromArray(pages)
.map(page -> new Pair<>(page, database.getPageBounds(page)))
.subscribeOn(Schedulers.computation());
}
示例7: getAyahCoordinates
import io.reactivex.Observable; //导入方法依赖的package包/类
public Observable<Pair<Integer, Map<String, List<AyahBounds>>>> getAyahCoordinates(
Integer... pages) {
AyahInfoDatabaseHandler database = ayahInfoDatabaseProvider.getAyahInfoHandler();
if (database == null) {
return Observable.error(new NoSuchElementException("No AyahInfoDatabaseHandler found!"));
}
return Observable.fromArray(pages)
.map(page -> new Pair<>(page, database.getVersesBoundsForPage(page)))
.subscribeOn(Schedulers.computation());
}
示例8: getLatestLocations
import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<Location> getLatestLocations() {
if (ContextCompat.checkSelfPermission(appContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
&& ContextCompat.checkSelfPermission(appContext, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
return Observable.just(googleApiClient)
.subscribeOn(Schedulers.newThread())
.doOnNext(this::initGoogleApiClient)
.doOnNext(client -> checkGoogleApiAvailability())
.map(this::getLocationSettingsStatus)
.doOnNext(this::checkSettingsStatus)
.flatMap(integer -> new LocationSniffer().startEmittingLocations());
}
return Observable.error(new PermissionException(Manifest.permission.ACCESS_FINE_LOCATION, ACCESS_LOCATION_PERMISSION_RESULT));
}
示例9: importSample
import io.reactivex.Observable; //导入方法依赖的package包/类
public Observable<String> importSample(SampleFile sample) {
try {
return importFile(sample.getSimplifiedName(), sample.openInputStream(), sample.getExtension());
} catch (IOException e) {
e.printStackTrace();
showMessage(R.string.text_import_fail);
return Observable.error(e);
}
}
示例10: execute
import io.reactivex.Observable; //导入方法依赖的package包/类
/**
* If the receiver is enabled, this method will:
* <p>
* 1. Invoke the `func` given at the time of creation.
* 2. Multicast the returned observable.
* 3. Send the multicasted observable on {@link #executionObservables()}.
* 4. Subscribe (connect) to the original observable on the main thread.
*
* @param input The input value to pass to the receiver's `func`. This may be null.
* @return the multicasted observable, after subscription. If the receiver is not
* enabled, returns a observable that will send an error.
*/
@MainThread
public final Observable<T> execute(@Nullable Object input) {
boolean enabled = mImmediateEnabled.blockingFirst();
if (!enabled) {
return Observable.error(new IllegalStateException("The command is disabled and cannot be executed"));
}
try {
Observable<T> observable = mFunc.apply(input);
if (observable == null) {
throw new RuntimeException(String.format("null Observable returned from observable func for value %s", input));
}
// This means that `executing` and `enabled` will send updated values before
// the observable actually starts performing work.
final ConnectableObservable<T> connection = observable
.subscribeOn(AndroidSchedulers.mainThread())
.replay();
mAddedExecutionObservableSubject.onNext(connection);
connection.connect();
return connection;
} catch (Exception e) {
e.printStackTrace();
return Observable.error(e);
}
}
示例11: getThrowObservable
import io.reactivex.Observable; //导入方法依赖的package包/类
private Observable<String> getThrowObservable() {
return Observable.error(new Callable<Throwable>() {
@Override
public Throwable call() throws Exception {
return new Throwable("throw error test");
}
});
}
示例12: getRecipe
import io.reactivex.Observable; //导入方法依赖的package包/类
@NonNull
public Observable<Recipe> getRecipe(int id) {
if (recipeCache == null) {
return Observable.error(new Throwable("Recipe not found."));
}
for (Recipe r : recipeCache) {
if (r.getId() == id) {
return Observable.just(r);
}
}
return Observable.error(new Throwable("Recipe not found."));
}
示例13: apply
import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<T> apply(@NonNull Throwable throwable) throws Exception {
//打印具体错误
LogUtils.e("HttpResultFunction:" + throwable);
return Observable.error(ExceptionEngine.handleException(throwable));
}
示例14: apply
import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<T> apply(@NonNull Throwable throwable) throws Exception {
return Observable.error(ApiException.handleException(throwable));
}
示例15: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
// TODO Auto-generated method stub
Observable<String> observable = Observable.error(new Exception("We got an Exception"));
observable.subscribe(item -> System.out.println("we got" + item),
error -> System.out.print(error));
}