mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-27 09:44:55 +03:00
parent
a9bfeb058b
commit
19bf47b6d2
2 changed files with 9 additions and 4 deletions
|
@ -233,7 +233,11 @@ class DownloadManager(private val context: Context, private val sourceManager: S
|
||||||
page.status = Page.DOWNLOAD_IMAGE
|
page.status = Page.DOWNLOAD_IMAGE
|
||||||
return source.getImageProgressResponse(page)
|
return source.getImageProgressResponse(page)
|
||||||
.flatMap({ resp ->
|
.flatMap({ resp ->
|
||||||
DiskUtils.saveBufferedSourceToDirectory(resp.body().source(), directory, filename)
|
try {
|
||||||
|
DiskUtils.saveBufferedSourceToDirectory(resp.body().source(), directory, filename)
|
||||||
|
} finally {
|
||||||
|
resp.body().close()
|
||||||
|
}
|
||||||
Observable.just(page)
|
Observable.just(page)
|
||||||
}).retry(2)
|
}).retry(2)
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,12 +56,12 @@ public final class DiskUtils {
|
||||||
try {
|
try {
|
||||||
bufferedSink = Okio.buffer(Okio.sink(writeFile));
|
bufferedSink = Okio.buffer(Okio.sink(writeFile));
|
||||||
bufferedSink.writeAll(bufferedSource);
|
bufferedSink.writeAll(bufferedSource);
|
||||||
|
Util.closeQuietly(bufferedSink);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Util.closeQuietly(bufferedSink);
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
writeFile.delete();
|
writeFile.delete();
|
||||||
throw new IOException("Unable to save image");
|
throw new IOException("Unable to save image");
|
||||||
} finally {
|
|
||||||
Util.closeQuietly(bufferedSink);
|
|
||||||
Util.closeQuietly(bufferedSource);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return writeFile;
|
return writeFile;
|
||||||
|
@ -74,6 +74,7 @@ public final class DiskUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
inputFile.delete();
|
inputFile.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue