@@ -92,6 +92,7 @@ public static class FileResult {
92
92
public String filePath ;
93
93
public String url ;
94
94
public ArrayList <KeyValuePair > headers ;
95
+
95
96
FileResult () {
96
97
}
97
98
}
@@ -584,11 +585,12 @@ public void onProgress(long loaded, long total) {
584
585
BufferedSink sink = null ;
585
586
try {
586
587
sink = Okio .buffer (Okio .sink (file ));
587
- sink .writeAll (Okio . source ( bufferedSource . inputStream ()) );
588
+ sink .writeAll (bufferedSource );
588
589
FileResult result = new FileResult ();
589
590
result .url = response .request ().url ().toString ();
590
591
result .headers = new ArrayList <>();
591
592
result .filePath = file .getAbsolutePath ();
593
+ sink .close ();
592
594
callback .onComplete (result );
593
595
} catch (StreamResetException e ) {
594
596
if (e .errorCode == ErrorCode .CANCEL ) {
@@ -615,9 +617,9 @@ public void onProgress(long loaded, long total) {
615
617
} catch (IOException e ) {
616
618
}
617
619
}
620
+ responseBody .close ();
621
+ downloadCallMap .remove (id );
618
622
}
619
-
620
- downloadCallMap .remove (id );
621
623
}
622
624
});
623
625
downloadCallMap .put (id , new DownloadCallOptions (call , options , callback ));
@@ -645,11 +647,11 @@ public void run() {
645
647
pair .call .cancel ();
646
648
}
647
649
648
- if (downloadPair != null ){
650
+ if (downloadPair != null ) {
649
651
downloadPair .call .cancel ();
650
652
}
651
653
652
- if (pair == null && downloadPair == null ){
654
+ if (pair == null && downloadPair == null ) {
653
655
cancelList .add (id );
654
656
}
655
657
}
0 commit comments