feat: WIP: use commons-compress

This commit is contained in:
huanghongxun
2021-10-23 01:47:10 +08:00
parent 5a9e8683e4
commit a36b0ebed2

View File

@@ -17,6 +17,7 @@
*/ */
package org.jackhuang.hmcl.util.io; package org.jackhuang.hmcl.util.io;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.jackhuang.hmcl.util.platform.OperatingSystem; import org.jackhuang.hmcl.util.platform.OperatingSystem;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -197,7 +198,9 @@ public final class CompressingUtils {
* @return the plain text content of given file. * @return the plain text content of given file.
*/ */
public static String readTextZipEntry(File zipFile, String name) throws IOException { 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. * @return the plain text content of given file.
*/ */
public static String readTextZipEntry(Path zipFile, String name, Charset encoding) throws IOException { public static String readTextZipEntry(Path zipFile, String name, Charset encoding) throws IOException {
try (FileSystem fs = createReadOnlyZipFileSystem(zipFile, encoding)) { try (ZipFile s = new ZipFile(zipFile.toFile(), encoding.name())) {
return FileUtils.readText(fs.getPath(name)); return IOUtils.readFullyAsString(s.getInputStream(s.getEntry(name)), StandardCharsets.UTF_8);
} }
} }