pull/2281/head
parent
2f276cf861
commit
9b4a3c1283
@ -0,0 +1,25 @@ |
||||
package io.legado.app.utils |
||||
|
||||
import java.io.InputStream |
||||
import java.util.* |
||||
|
||||
fun InputStream?.isJson(): Boolean { |
||||
this ?: return false |
||||
this.use { |
||||
val byteArray = ByteArray(128) |
||||
it.read(byteArray) |
||||
val a = String(byteArray).trim() |
||||
it.skip(it.available() - 128L) |
||||
it.read(byteArray) |
||||
val b = String(byteArray).trim() |
||||
return (a + b).isJson() |
||||
} |
||||
} |
||||
|
||||
fun InputStream?.contains(str: String): Boolean { |
||||
this ?: return false |
||||
this.use { |
||||
val scanner = Scanner(it) |
||||
return scanner.findWithinHorizon(str, 0) != null |
||||
} |
||||
} |
Loading…
Reference in new issue