diff --git a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/util/system/ZipEngine.java b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/util/system/ZipEngine.java index 8c28853de..a4bf5d52b 100644 --- a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/util/system/ZipEngine.java +++ b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/util/system/ZipEngine.java @@ -25,6 +25,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.HashSet; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import org.jackhuang.hellominecraft.util.func.BiFunction; @@ -100,7 +101,7 @@ public class ZipEngine { pathName = pathNameCallback.apply(pathName, true); if (pathName == null) continue; - zos.putNextEntry(new ZipEntry(pathName)); + put(new ZipEntry(pathName)); putDirectoryImpl(file, basePath, pathNameCallback); } else { if (".DS_Store".equals(file.getName())) // For Mac computers. @@ -122,7 +123,7 @@ public class ZipEngine { public void putStream(InputStream is, String pathName) throws IOException { int length; try (BufferedInputStream bis = new BufferedInputStream(is)) { - zos.putNextEntry(new ZipEntry(pathName)); + put(new ZipEntry(pathName)); while ((length = bis.read(buf)) > 0) zos.write(buf, 0, length); } @@ -136,4 +137,11 @@ public class ZipEngine { putStream(new ByteArrayInputStream(text.getBytes(encoding)), pathName); } + protected HashSet names = new HashSet<>(); + + public void put(ZipEntry entry) throws IOException { + if (names.add(entry.getName())) + zos.putNextEntry(entry); + } + }