Skip to content

Commit 79d753c

Browse files
committed
Change to io executor, remove delete temp file and nit changes
1 parent 4118316 commit 79d753c

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

Parse/src/main/java/com/parse/ParseFileController.java

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public File getCacheFile(ParseFile.State state) {
6060
if (state.url() == null) {
6161
return null;
6262
}
63-
return new File(cachePath, state.url()+".tmp");
63+
return new File(cachePath, state.url() + ".tmp");
6464
}
6565

6666
public boolean isDataAvailable(ParseFile.State state) {
@@ -121,7 +121,7 @@ public ParseFile.State then(Task<JSONObject> task) throws Exception {
121121

122122
return newState;
123123
}
124-
}, Task.BACKGROUND_EXECUTOR);
124+
}, ParseExecutors.io());
125125
}
126126

127127
public Task<File> fetchAsync(
@@ -138,7 +138,7 @@ public Task<File> fetchAsync(
138138
public Boolean call() throws Exception {
139139
return cacheFile.exists();
140140
}
141-
}, Task.BACKGROUND_EXECUTOR).continueWithTask(new Continuation<Boolean, Task<File>>() {
141+
}, ParseExecutors.io()).continueWithTask(new Continuation<Boolean, Task<File>>() {
142142
@Override
143143
public Task<File> then(Task<Boolean> task) throws Exception {
144144
boolean result = task.getResult();
@@ -156,25 +156,16 @@ public Task<File> then(Task<Boolean> task) throws Exception {
156156
// this incomplete cacheFile
157157
final File tempFile = getTempFile(state);
158158

159-
return Task.call(new Callable<Void>() {
160-
@Override
161-
public Void call() throws Exception {
162-
// If the last download is interrupted, there may be incomplete temp file in disk. So
163-
// we need to clear it first.
164-
ParseFileUtils.deleteQuietly(tempFile);
165-
return null;
166-
}
167-
}).continueWithTask(new Continuation<Void, Task<Void>>() {
168-
@Override
169-
public Task<Void> then(Task<Void> task) throws Exception {
170-
// network
171-
final ParseAWSRequest request =
172-
new ParseAWSRequest(ParseRequest.Method.GET, state.url(), tempFile);
159+
// network
160+
final ParseAWSRequest request =
161+
new ParseAWSRequest(ParseRequest.Method.GET, state.url(), tempFile);
173162

174-
return request.executeAsync(
175-
awsClient(), null, downloadProgressCallback, cancellationToken);
176-
}
177-
}).continueWithTask(new Continuation<Void, Task<File>>() {
163+
// We do not need to delete the temp file since we always try to overwrite it
164+
return request.executeAsync(
165+
awsClient(),
166+
null,
167+
downloadProgressCallback,
168+
cancellationToken).continueWithTask(new Continuation<Void, Task<File>>() {
178169
@Override
179170
public Task<File> then(Task<Void> task) throws Exception {
180171
// If the top-level task was cancelled, don't actually set the data -- just move on.
@@ -189,7 +180,7 @@ public Task<File> then(Task<Void> task) throws Exception {
189180
ParseFileUtils.moveFile(tempFile, cacheFile);
190181
return Task.forResult(cacheFile);
191182
}
192-
});
183+
}, ParseExecutors.io());
193184
}
194185
});
195186
}

0 commit comments

Comments
 (0)