當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。