Skip to content

Commit 5bcd0da

Browse files
author
krishna
committed
delete the half downloaded file
1 parent cc3960d commit 5bcd0da

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fileloader/src/main/java/com/krishna/fileloader/network/FileDownloader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ public File download(boolean autoRefresh) throws Exception {
8686

8787
//write the body to file
8888
BufferedSink sink = Okio.buffer(Okio.sink(downloadFilePath));
89-
sink.writeAll(response.body().source());
89+
long readBytes = sink.writeAll(response.body().source());
9090
sink.close();
9191

9292
//check if downloaded file is not corrupt
93-
if (downloadFilePath.length() < response.body().contentLength()) {
93+
if (readBytes < response.body().contentLength()) {
9494
//delete the corrupt file
9595
downloadFilePath.delete();
9696
throw new IOException("Failed to download file: " + response);

0 commit comments

Comments
 (0)