@@ -60,7 +60,7 @@ public File getCacheFile(ParseFile.State state) {
60
60
if (state .url () == null ) {
61
61
return null ;
62
62
}
63
- return new File (cachePath , state .url ()+ ".tmp" );
63
+ return new File (cachePath , state .url () + ".tmp" );
64
64
}
65
65
66
66
public boolean isDataAvailable (ParseFile .State state ) {
@@ -121,7 +121,7 @@ public ParseFile.State then(Task<JSONObject> task) throws Exception {
121
121
122
122
return newState ;
123
123
}
124
- }, Task . BACKGROUND_EXECUTOR );
124
+ }, ParseExecutors . io () );
125
125
}
126
126
127
127
public Task <File > fetchAsync (
@@ -138,7 +138,7 @@ public Task<File> fetchAsync(
138
138
public Boolean call () throws Exception {
139
139
return cacheFile .exists ();
140
140
}
141
- }, Task . BACKGROUND_EXECUTOR ).continueWithTask (new Continuation <Boolean , Task <File >>() {
141
+ }, ParseExecutors . io () ).continueWithTask (new Continuation <Boolean , Task <File >>() {
142
142
@ Override
143
143
public Task <File > then (Task <Boolean > task ) throws Exception {
144
144
boolean result = task .getResult ();
@@ -156,25 +156,16 @@ public Task<File> then(Task<Boolean> task) throws Exception {
156
156
// this incomplete cacheFile
157
157
final File tempFile = getTempFile (state );
158
158
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 );
173
162
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 >>() {
178
169
@ Override
179
170
public Task <File > then (Task <Void > task ) throws Exception {
180
171
// 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 {
189
180
ParseFileUtils .moveFile (tempFile , cacheFile );
190
181
return Task .forResult (cacheFile );
191
182
}
192
- });
183
+ }, ParseExecutors . io () );
193
184
}
194
185
});
195
186
}
0 commit comments