当前位置: 首页>>代码示例>>Java>>正文


Java Observable.error方法代码示例

本文整理汇总了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();
  }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:SearchEngine.java

示例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);
                }
            });
}
 
开发者ID:florent37,项目名称:AndroidMVPresenter,代码行数:19,代码来源:MainPresenter.java

示例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");
}
 
开发者ID:PacktPublishing,项目名称:Reactive-Programming-With-Java-9,代码行数:17,代码来源:Modern_Testing.java

示例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);
    }
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:10,代码来源:ScriptOperations.java

示例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);
    }
}
 
开发者ID:amvnetworks,项目名称:amv-access-api-poc,代码行数:29,代码来源:ResponseHelper.java

示例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());
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:11,代码来源:CoordinatesModel.java

示例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());
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:12,代码来源:CoordinatesModel.java

示例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));
}
 
开发者ID:titanium-codes,项目名称:LocGetter,代码行数:15,代码来源:LocationGetterImpl.java

示例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);
    }
}
 
开发者ID:hyb1996,项目名称:Auto.js,代码行数:10,代码来源:ScriptOperations.java

示例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);
    }
}
 
开发者ID:listenzz,项目名称:RxCommand,代码行数:39,代码来源:RxCommand.java

示例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");
        }
    });
}
 
开发者ID:changjiashuai,项目名称:RxJava2-Android-Sample,代码行数:9,代码来源:EmptyNeverThrowExampleActivity.java

示例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."));
}
 
开发者ID:AndrejJurkin,项目名称:udacity-baking-app-mvvm-rxjava-dagger,代码行数:15,代码来源:RecipeRepository.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:HttpResultFunction.java

示例14: apply

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<T> apply(@NonNull Throwable throwable) throws Exception {
    return Observable.error(ApiException.handleException(throwable));
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:5,代码来源:HttpResponseFunc.java

示例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));
}
 
开发者ID:PacktPublishing,项目名称:Reactive-Programming-With-Java-9,代码行数:7,代码来源:DemoObservable_error.java


注:本文中的io.reactivex.Observable.error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。