/** * Asynchronously gets the file pointer from cache if available or fetches its content from the * network. * <strong>Note: </strong> The {@link File} location may change without notice and should not be * stored to be accessed later. * * @return A Task that is resolved when the data has been fetched. */ public Task<File> getFileInBackground() { return getFileInBackground((ProgressCallback) null); }
/** * Synchronously gets the file pointer from cache if available or fetches its content from the * network. You probably want to use {@link #getFileInBackground()} instead unless you're already * in a background thread. * <strong>Note: </strong> The {@link File} location may change without notice and should not be * stored to be accessed later. */ public File getFile() throws ParseException { return ParseTaskUtils.wait(getFileInBackground()); }
/** * Asynchronously gets the file pointer from cache if available or fetches its content from the * network. The {@code GetFileCallback} will be called when the get completes. * <strong>Note: </strong> The {@link File} location may change without notice and should not be * stored to be accessed later. * * @param fileCallback A {@code GetFileCallback} that is called when the get completes. */ public void getFileInBackground(GetFileCallback fileCallback) { ParseTaskUtils.callbackOnMainThreadAsync(getFileInBackground(), fileCallback); }
/** * Asynchronously gets the file pointer from cache if available or fetches its content from the * network. The {@code GetFileCallback} will be called when the get completes. * The {@code ProgressCallback} will be called periodically with progress updates. * The {@code ProgressCallback} is guaranteed to be called with 100 before the * {@code GetFileCallback} is called. * <strong>Note: </strong> The {@link File} location may change without notice and should not be * stored to be accessed later. * * @param fileCallback A {@code GetFileCallback} that is called when the get completes. * @param progressCallback A {@code ProgressCallback} that is called periodically with progress updates. */ public void getFileInBackground(GetFileCallback fileCallback, final ProgressCallback progressCallback) { ParseTaskUtils.callbackOnMainThreadAsync(getFileInBackground(progressCallback), fileCallback); }
ParseFile parseFile = new ParseFile(state); File fetchedFile = ParseTaskUtils.wait(parseFile.getFileInBackground()); File fetchedFileAgain = ParseTaskUtils.wait(parseFile.getFileInBackground());
@NonNull @CheckReturnValue public static Single<File> getFile(@NonNull final ParseFile file) { return RxTask.single(() -> file.getFileInBackground()); }
@NonNull @CheckReturnValue public static Single<File> getFile(@NonNull final ParseFile file, @NonNull final ProgressCallback progressCallback) { return RxTask.single(() -> file.getFileInBackground(progressCallback)); }
@Test public void testParseObservableGetFileProgress() { rx.parse2.ParseObservable.getFile(mocker(ParseFile.class) .when(it -> it.getFileInBackground(any(ProgressCallback.class))) .thenReturn(it -> Task.forResult(new File("/"))) .mock(), mock(ProgressCallback.class)) .test() .assertNoErrors() .assertComplete(); }
@Test public void testParseObservableGetFile() { rx.parse2.ParseObservable.getFile(mocker(ParseFile.class) .when(it -> it.getFileInBackground()) .thenReturn(it -> Task.forResult(new File("/"))) .mock()) .test() .assertNoErrors() .assertComplete(); }