Address some OkHttp nullability issues

This commit is contained in:
Jobobby04
2022-09-03 19:55:30 -04:00
parent 0c1ac913cb
commit 6e1e42fefd
10 changed files with 14 additions and 15 deletions
@@ -169,12 +169,12 @@ class PagePreviewCache(private val context: Context) {
editor = diskCache.edit(key) ?: throw IOException("Unable to edit key")
// Get OutputStream and write page with Okio.
response.body!!.source().saveTo(editor.newOutputStream(0))
response.body.source().saveTo(editor.newOutputStream(0))
diskCache.flush()
editor.commit()
} finally {
response.body?.close()
response.body.close()
editor?.abortUnlessCommitted()
}
}
@@ -1087,7 +1087,7 @@ class EHentai(
.url(EH_API_BASE)
.post(json.toString().toRequestBody(JSON))
.build(),
).execute().body!!.string(),
).execute().body.string(),
)
val obj = outJson["tokenlist"]!!.jsonArray.first().jsonObject
@@ -1216,7 +1216,7 @@ class EHentai(
if (response.isSuccessful) {
val body = ByteArrayOutputStream()
.use {
val bitmap = BitmapFactory.decodeStream(response.body!!.byteStream())
val bitmap = BitmapFactory.decodeStream(response.body.byteStream())
?: throw IOException("Null bitmap($thumbnailPreview)")
Bitmap.createBitmap(
bitmap,
@@ -62,7 +62,7 @@ class NHentai(delegate: HttpSource, val context: Context) :
}
override suspend fun parseIntoMetadata(metadata: NHentaiSearchMetadata, input: Response) {
val json = GALLERY_JSON_REGEX.find(input.body?.string().orEmpty())!!.groupValues[1].replace(
val json = GALLERY_JSON_REGEX.find(input.body.string())!!.groupValues[1].replace(
UNICODE_ESCAPE_REGEX,
) { it.groupValues[1].toInt(radix = 16).toChar().toString() }
val jsonResponse = jsonParser.decodeFromString<JsonResponse>(json)