code

原创
2019/08/27 16:51
阅读数 80
Flowable.create(new FlowableOnSubscribe<Response<MasterDataResponse>>() {
            @Override
            public void subscribe(FlowableEmitter<Response<MasterDataResponse>> emitter) throws Exception {
                Timber.i("thread name is ****** " + Thread.currentThread().getName());
                MasterDataResponse masterDataResponseResponse;
                try {
                    InputStream myInput = BmwApplication.getInstance().getAssets().open(ScanCardConstants.MASTER_DATA_NAME);
                    ByteArrayOutputStream result = new ByteArrayOutputStream();
                    byte[] buffer = new byte[1024];
                    int length;
                    while ((length = myInput.read(buffer)) > 0) {
                        result.write(buffer, 0, length);
                    }

                    myInput.close();
                    String masterData = result.toString("UTF-8");
                    masterDataResponseResponse = new Gson().fromJson(masterData, MasterDataResponse.class);
                    emitter.onNext(Response.success(masterDataResponseResponse));
                } catch (IOException e) {
                    Timber.e(e, "provideScanUserIdLicense");
                }

            }
        }, BackpressureStrategy.ERROR).subscribeOn(Schedulers.computation());
    private Flowable<Response<MasterDataResponse>> getSalesConsultantFlowableData() {
        return Flowable.create((FlowableEmitter<Response<MasterDataResponse>> emitter) -> {
            Timber.i("thread name is ****** " + Thread.currentThread().getName());
            MasterDataResponse masterDataResponseResponse;
            try {
                InputStream myInput = BmwApplication.getInstance().getAssets().open(ScanCardConstants.MASTER_DATA_NAME);
                ByteArrayOutputStream result = new ByteArrayOutputStream();
                byte[] buffer = new byte[1024];
                int length;
                while ((length = myInput.read(buffer)) > 0) {
                    result.write(buffer, 0, length);
                }

                myInput.close();
                String masterData = result.toString("UTF-8");
                masterDataResponseResponse = new Gson().fromJson(masterData, MasterDataResponse.class);
                emitter.onNext(Response.success(masterDataResponseResponse));
            } catch (IOException e) {
                Timber.e(e, "provideScanUserIdLicense");
            }
        }, BackpressureStrategy.ERROR).subscribeOn(Schedulers.computation());
    }

HomeTodayTaskFragment

onstart() {

//请求今日任务接口
}

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部