parent
0dc74f9188
commit
5fe40ac17e
@ -1,30 +1,30 @@
|
|||||||
package org.koitharu.kotatsu.utils.ext
|
package org.koitharu.kotatsu.utils.ext
|
||||||
|
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import okhttp3.internal.closeQuietly
|
import okhttp3.internal.Util.closeQuietly
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
import org.jsoup.nodes.Document
|
import org.jsoup.nodes.Document
|
||||||
|
|
||||||
fun Response.parseHtml(): Document {
|
fun Response.parseHtml(): Document {
|
||||||
try {
|
try {
|
||||||
val stream = body?.byteStream() ?: throw NullPointerException("Response body is null")
|
val stream = body()?.byteStream() ?: throw NullPointerException("Response body is null")
|
||||||
val charset = body!!.contentType()?.charset()?.name()
|
val charset = body()!!.contentType()?.charset()?.name()
|
||||||
return Jsoup.parse(
|
return Jsoup.parse(
|
||||||
stream,
|
stream,
|
||||||
charset,
|
charset,
|
||||||
request.url.toString()
|
request().url().toString()
|
||||||
)
|
)
|
||||||
} finally {
|
} finally {
|
||||||
closeQuietly()
|
closeQuietly(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Response.parseJson(): JSONObject {
|
fun Response.parseJson(): JSONObject {
|
||||||
try {
|
try {
|
||||||
val string = body?.string() ?: throw NullPointerException("Response body is null")
|
val string = body()?.string() ?: throw NullPointerException("Response body is null")
|
||||||
return JSONObject(string)
|
return JSONObject(string)
|
||||||
} finally {
|
} finally {
|
||||||
closeQuietly()
|
closeQuietly(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 319 B |
Binary file not shown.
|
After Width: | Height: | Size: 162 B |
Binary file not shown.
|
After Width: | Height: | Size: 254 B |
Binary file not shown.
|
After Width: | Height: | Size: 534 B |
Binary file not shown.
|
After Width: | Height: | Size: 462 B |
Loading…
Reference in New Issue