我正在下载一个改装的pdf文件,我下载它的方式是块.我使用Content-Range头来获取一个字节范围,然后我需要写这些字节file的问题是编写它们的顺序.我正在使用该flatMap()函数为每个下载文件必须完成的请求返回一个observable.
.flatMap(new Func1<Integer, Observable<Response>>() {
@Override
public Observable<Response> call(Integer offset) {
int end;
if (offset + BLOCK_SIZE > (contentLength - 1))
end = (int) contentLength - 1 - offset;
else
end = offset + BLOCK_SIZE;
String range = getResources().getString(R.string.range_format, offset, end);
return ApiAdapter.getApiService().downloadPDFBlock(range);
}
})
Run Code Online (Sandbox Code Playgroud)
在downloadPDFBlock接收由一个标题需要一个字符串:Range: bytes=0-3999.然后我使用subscribe函数写下载的字节
subscribe(new Subscriber<Response>() {
@Override
public void onCompleted() {
Log.i(LOG_TAG, file.getAbsolutePath());
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onNext(Response …Run Code Online (Sandbox Code Playgroud)