Skip to content

Commit f3afdee

Browse files
committed
fix(android): clean up
1 parent 7061f63 commit f3afdee

File tree

1 file changed

+7
-5
lines changed
  • src/platforms/android/java/com/github/triniwiz/async

1 file changed

+7
-5
lines changed

src/platforms/android/java/com/github/triniwiz/async/Async.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public static class FileResult {
9292
public String filePath;
9393
public String url;
9494
public ArrayList<KeyValuePair> headers;
95+
9596
FileResult() {
9697
}
9798
}
@@ -584,11 +585,12 @@ public void onProgress(long loaded, long total) {
584585
BufferedSink sink = null;
585586
try {
586587
sink = Okio.buffer(Okio.sink(file));
587-
sink.writeAll(Okio.source(bufferedSource.inputStream()));
588+
sink.writeAll(bufferedSource);
588589
FileResult result = new FileResult();
589590
result.url = response.request().url().toString();
590591
result.headers = new ArrayList<>();
591592
result.filePath = file.getAbsolutePath();
593+
sink.close();
592594
callback.onComplete(result);
593595
} catch (StreamResetException e) {
594596
if (e.errorCode == ErrorCode.CANCEL) {
@@ -615,9 +617,9 @@ public void onProgress(long loaded, long total) {
615617
} catch (IOException e) {
616618
}
617619
}
620+
responseBody.close();
621+
downloadCallMap.remove(id);
618622
}
619-
620-
downloadCallMap.remove(id);
621623
}
622624
});
623625
downloadCallMap.put(id, new DownloadCallOptions(call, options, callback));
@@ -645,11 +647,11 @@ public void run() {
645647
pair.call.cancel();
646648
}
647649

648-
if(downloadPair != null){
650+
if (downloadPair != null) {
649651
downloadPair.call.cancel();
650652
}
651653

652-
if(pair == null && downloadPair == null){
654+
if (pair == null && downloadPair == null) {
653655
cancelList.add(id);
654656
}
655657
}

0 commit comments

Comments
 (0)