DownloadServiceImpl implements DownloadService { @Override public Observable<DownloadProgressItem> downloadFile(final FireBookDetails book) { if (book.isDownloadedAlready()) { return getBookPagesFromDownloadedBook(book); } try { final File localFile; Uri uri = Uri.parse(book.getBookUrl()); String tempFileName = uri.getLastPathSegment(); String tempFileParsed[] = tempFileName.split("/"); tempFileName = tempFileParsed[tempFileParsed.length - 1]; localFile = File.createTempFile(tempFileName, ""); return RxFirebaseStorage.getFile(book.getBookUrlStorageRef(), localFile) .flatMap(new Func1<FileDownloadTask.TaskSnapshot, Observable<DownloadProgressItem>>() { @Override public Observable<DownloadProgressItem> call(FileDownloadTask.TaskSnapshot taskSnapshot) { DownloadProgressItem downloadProgressItem = new DownloadProgressItem( taskSnapshot.getBytesTransferred(), taskSnapshot.getTotalByteCount()); if (downloadProgressItem.isComplete()) { return Observable .defer(new TransformFileIntoBookPages(downloadProgressItem, localFile, book)); } return Observable.just(downloadProgressItem); } }); } catch (Exception e) { Log.e(TAG, "IOException downloading file", e); return Observable.error(e); } } DownloadServiceImpl(FirebaseStorage firebaseStorageRef); @Override Observable<DownloadProgressItem> downloadFile(final FireBookDetails book); Observable<Boolean> deleteDownload(final FireBookDetails bookToDelete); static final String TAG; }
@Test public void testDownloadFile() throws Exception { }