From b9967c52bac96b53af865bbb48943ab92fd851d5 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 21 Jul 2021 14:44:37 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96zip=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=88=A4=E6=96=AD=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/JsExtensions.kt | 29 +++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index eb0f4cda8..60580566f 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -19,6 +19,7 @@ import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.io.File import java.net.URLEncoder +import java.nio.charset.Charset import java.util.* import java.util.zip.ZipEntry import java.util.zip.ZipInputStream @@ -319,28 +320,14 @@ interface JsExtensions { * @return zip指定文件的数据 */ fun getZipStringContent(url: String, path: String): String { - val bytes = if (url.startsWith("http://") || url.startsWith("https://")) { - runBlocking { - return@runBlocking okHttpClient.newCall { url(url) }.bytes() - } - } else { - StringUtils.hexStringToByte(url) - } - val bos = ByteArrayOutputStream() - val zis = ZipInputStream(ByteArrayInputStream(bytes)) - - var entry: ZipEntry? = zis.nextEntry - - while (entry != null) { - if (entry.name.equals(path)) { - zis.use { it.copyTo(bos) } - return bos.toString() - } - entry = zis.nextEntry - } - Debug.log("getZipContent 未发现内容") + val byteArray = getZipByteArrayContent(url, path) ?: return "" + val charsetName = EncodingDetect.getEncode(byteArray) + return String(byteArray, Charset.forName(charsetName)) + } - return "" + fun getZipStringContent(url: String, path: String, charsetName: String): String { + val byteArray = getZipByteArrayContent(url, path) ?: return "" + return String(byteArray, Charset.forName(charsetName)) } /**