From a36b0ebed2a6b137d8224812e584c834746db876 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Sat, 23 Oct 2021 01:47:10 +0800 Subject: [PATCH] feat: WIP: use commons-compress --- .../org/jackhuang/hmcl/util/io/CompressingUtils.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/CompressingUtils.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/CompressingUtils.java index 3044d3e0d..b955afa92 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/CompressingUtils.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/CompressingUtils.java @@ -17,6 +17,7 @@ */ package org.jackhuang.hmcl.util.io; +import org.apache.commons.compress.archivers.zip.ZipFile; import org.jackhuang.hmcl.util.platform.OperatingSystem; import org.jetbrains.annotations.NotNull; @@ -197,7 +198,9 @@ public final class CompressingUtils { * @return the plain text content of given file. */ public static String readTextZipEntry(File zipFile, String name) throws IOException { - return readTextZipEntry(zipFile.toPath(), name, null); + try (ZipFile s = new ZipFile(zipFile)) { + return IOUtils.readFullyAsString(s.getInputStream(s.getEntry(name)), StandardCharsets.UTF_8); + } } /** @@ -209,8 +212,8 @@ public final class CompressingUtils { * @return the plain text content of given file. */ public static String readTextZipEntry(Path zipFile, String name, Charset encoding) throws IOException { - try (FileSystem fs = createReadOnlyZipFileSystem(zipFile, encoding)) { - return FileUtils.readText(fs.getPath(name)); + try (ZipFile s = new ZipFile(zipFile.toFile(), encoding.name())) { + return IOUtils.readFullyAsString(s.getInputStream(s.getEntry(name)), StandardCharsets.UTF_8); } }