Several reader fixes

This commit is contained in:
inorichi
2018-09-08 12:44:35 +02:00
parent 18f89cc341
commit 116f7d1c4a
9 changed files with 52 additions and 74 deletions

View File

@@ -6,16 +6,12 @@ import java.net.URLConnection
object ImageUtil {
fun isImage(name: String, openStream: (() -> InputStream)? = null): Boolean {
try {
val guessedMime = URLConnection.guessContentTypeFromName(name)
if (guessedMime.startsWith("image/")) {
return true
}
val contentType = try {
URLConnection.guessContentTypeFromName(name)
} catch (e: Exception) {
/* Ignore error */
}
return openStream?.let { findImageType(it) } != null
null
} ?: openStream?.let { findImageType(it)?.mime }
return contentType?.startsWith("image/") ?: false
}
fun findImageType(openStream: () -> InputStream): ImageType? {