Source:
public Task<File> fetchAsync( final ParseFile.State state, @SuppressWarnings("UnusedParameters") String sessionToken, final ProgressCallback downloadProgressCallback, final Task<Void> cancellationToken) { if (cancellationToken != null && cancellationToken.isCancelled()) { return Task.cancelled(); } final File cacheFile = getCacheFile(state); return Task.call(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return cacheFile.exists(); } }, Task.BACKGROUND_EXECUTOR).continueWithTask(new Continuation<Boolean, Task<File>>() { @Override public Task<File> then(Task<Boolean> task) throws Exception { boolean result = task.getResult(); if (result) { return Task.forResult(cacheFile); } if (cancellationToken != null && cancellationToken.isCancelled()) { return Task.cancelled(); } final File tempFile = getTempFile(state); return Task.call(new Callable<Void>() { @Override public Void call() throws Exception { ParseFileUtils.deleteQuietly(tempFile); return null; } }).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) throws Exception { final ParseAWSRequest request = new ParseAWSRequest(ParseRequest.Method.GET, state.url(), tempFile); return request.executeAsync( awsClient(), null, downloadProgressCallback, cancellationToken); } }).continueWithTask(new Continuation<Void, Task<File>>() { @Override public Task<File> then(Task<Void> task) throws Exception { if (cancellationToken != null && cancellationToken.isCancelled()) { throw new CancellationException(); } if (task.isFaulted()) { ParseFileUtils.deleteQuietly(tempFile); return task.cast(); } ParseFileUtils.moveFile(tempFile, cacheFile); return Task.forResult(cacheFile); } }); } }); }

Target:
public Task<File> fetchAsync( final ParseFile.State state, @SuppressWarnings("UnusedParameters") String sessionToken, final ProgressCallback downloadProgressCallback, final Task<Void> cancellationToken) { if (cancellationToken != null && cancellationToken.isCancelled()) { return Task.cancelled(); } final File cacheFile = getCacheFile(state); return Task.call(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return cacheFile.exists(); } }, ParseExecutors.io()).continueWithTask(new Continuation<Boolean, Task<File>>() { @Override public Task<File> then(Task<Boolean> task) throws Exception { boolean result = task.getResult(); if (result) { return Task.forResult(cacheFile); } if (cancellationToken != null && cancellationToken.isCancelled()) { return Task.cancelled(); } final File tempFile = getTempFile(state); final ParseAWSRequest request = new ParseAWSRequest(ParseHttpRequest.Method.GET, state.url(), tempFile); return request.executeAsync( awsClient(), null, downloadProgressCallback, cancellationToken).continueWithTask(new Continuation<Void, Task<File>>() { @Override public Task<File> then(Task<Void> task) throws Exception { if (cancellationToken != null && cancellationToken.isCancelled()) { throw new CancellationException(); } if (task.isFaulted()) { ParseFileUtils.deleteQuietly(tempFile); return task.cast(); } ParseFileUtils.moveFile(tempFile, cacheFile); return Task.forResult(cacheFile); } }, ParseExecutors.io()); } }); }