Albirew/tachiyomi
Archivé
1
0
Bifurcation 0

Always close response body

Cette révision appartient à :
len 2016-04-19 14:08:35 +02:00
Parent 447dfd1e3c
révision 9213fc6999
3 fichiers modifiés avec 12 ajouts et 12 suppressions

Voir le fichier

@ -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()
}
}

Voir le fichier

@ -44,21 +44,21 @@ class NetworkHelper(context: Context) {
@JvmOverloads
fun request(request: Request, forceCache: Boolean = false): Observable<Response> {
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<String> {
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<Response> {
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

Voir le fichier

@ -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;