diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt index 1ff58e6f3..8225472bd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt @@ -202,9 +202,9 @@ class ChapterCache(private val context: Context) { diskCache.flush() editor.commit() } catch (e: Exception) { - response.body().close() throw IOException("Unable to save image") } finally { + response.body().close() editor?.abortUnlessCommitted() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/network/NetworkHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/network/NetworkHelper.kt index baeb10464..e65d8ee23 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/network/NetworkHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/network/NetworkHelper.kt @@ -44,21 +44,21 @@ class NetworkHelper(context: Context) { @JvmOverloads fun request(request: Request, forceCache: Boolean = false): Observable { - var response: Response? = null return Observable.fromCallable { val c = if (forceCache) forceCacheClient else client - c.newCall(request).execute().apply { response = this } - }.doOnUnsubscribe { response?.body()?.close() } + c.newCall(request).execute().apply { body().close() } + } } @JvmOverloads fun requestBody(request: Request, forceCache: Boolean = false): Observable { - return request(request, forceCache) - .map { it.body().string() } + return Observable.fromCallable { + val c = if (forceCache) forceCacheClient else client + c.newCall(request).execute().body().string() + } } fun requestBodyProgress(request: Request, listener: ProgressListener): Observable { - var response: Response? = null return Observable.fromCallable { val progressClient = client.newBuilder() .cache(null) @@ -70,8 +70,8 @@ class NetworkHelper(context: Context) { } .build() - progressClient.newCall(request).execute().apply { response = this } - }.doOnUnsubscribe { response?.body()?.close() }.retry(1) + progressClient.newCall(request).execute() + } } val cookies: CookieStore diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/DiskUtils.java b/app/src/main/java/eu/kanade/tachiyomi/util/DiskUtils.java index ea2d83ddd..c529b8eaa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/DiskUtils.java +++ b/app/src/main/java/eu/kanade/tachiyomi/util/DiskUtils.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import okhttp3.internal.Util; import okio.BufferedSink; import okio.BufferedSource; import okio.Okio; @@ -59,9 +60,8 @@ public final class DiskUtils { writeFile.delete(); throw new IOException("Unable to save image"); } finally { - if (bufferedSink != null) { - bufferedSink.close(); - } + Util.closeQuietly(bufferedSink); + Util.closeQuietly(bufferedSource); } return writeFile;