/** * Asynchronously gets the data stream from cached file if available or fetches its content from * the network, saves the content as cached file and returns the data stream of the cached file. * * @return A Task that is resolved when the data stream has been fetched. */ public Task<InputStream> getDataStreamInBackground() { return getDataStreamInBackground((ProgressCallback) null); }
/** * Synchronously gets the data stream from cached file if available or fetches its content from * the network, saves the content as cached file and returns the data stream of the cached file. * You probably want to use {@link #getDataStreamInBackground} instead unless you're already in a * background thread. */ public InputStream getDataStream() throws ParseException { return ParseTaskUtils.wait(getDataStreamInBackground()); }
/** * Asynchronously gets the data stream from cached file if available or fetches its content from * the network, saves the content as cached file and returns the data stream of the cached file. * The {@code GetDataStreamCallback} will be called when the get completes. * * @param dataStreamCallback A {@code GetDataStreamCallback} that is called when the get completes. */ public void getDataStreamInBackground(GetDataStreamCallback dataStreamCallback) { ParseTaskUtils.callbackOnMainThreadAsync(getDataStreamInBackground(), dataStreamCallback); }
/** * Asynchronously gets the data stream from cached file if available or fetches its content from * the network, saves the content as cached file and returns the data stream of the cached file. * The {@code GetDataStreamCallback} 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 * {@code GetDataStreamCallback} is called. * * @param dataStreamCallback A {@code GetDataStreamCallback} that is called when the get completes. * @param progressCallback A {@code ProgressCallback} that is called periodically with progress updates. */ public void getDataStreamInBackground(GetDataStreamCallback dataStreamCallback, final ProgressCallback progressCallback) { ParseTaskUtils.callbackOnMainThreadAsync( getDataStreamInBackground(progressCallback), dataStreamCallback); }
ParseFile parseFile = new ParseFile(state); InputStream dataStream = ParseTaskUtils.wait(parseFile.getDataStreamInBackground()); InputStream dataStreamAgain = ParseTaskUtils.wait(parseFile.getDataStreamInBackground());
@NonNull @CheckReturnValue public static Single<InputStream> getDataStream(@NonNull final ParseFile file) { return RxTask.single(() -> file.getDataStreamInBackground()); }
@NonNull @CheckReturnValue public static Single<InputStream> getDataStream(@NonNull final ParseFile file, @NonNull final ProgressCallback progressCallback) { return RxTask.single(() -> file.getDataStreamInBackground(progressCallback)); }
@Test public void testParseObservableGetDataStreamProgress() { rx.parse2.ParseObservable.getDataStream(mocker(ParseFile.class) .when(it -> it.getDataStreamInBackground(any(ProgressCallback.class))) .thenReturn(it -> Task.forResult(mock(InputStream.class))) .mock(), mock(ProgressCallback.class)) .test() .assertNoErrors() .assertComplete(); }
@Test public void testParseObservableGetDataStream() { rx.parse2.ParseObservable.getDataStream(mocker(ParseFile.class) .when(it -> it.getDataStreamInBackground()) .thenReturn(it -> Task.forResult(mock(InputStream.class))) .mock()) .test() .assertNoErrors() .assertComplete(); }