|
|
@@ -278,16 +278,23 @@ public final class JarUtil {
|
|
|
ZipEntry zipEntry = entries.nextElement();
|
|
|
zipEntryList.add(zipEntry);
|
|
|
}
|
|
|
+
|
|
|
+ Map<String, byte[]> originBytesMap = new HashMap<>(64);
|
|
|
+ for (ZipEntry zipEntry : zipEntryList) {
|
|
|
+ String zipEntryName = zipEntry.getName();
|
|
|
+ byte[] originBytes = IOUtil.toBytes(zipFile.getInputStream(zipEntry));
|
|
|
+ originBytesMap.put(zipEntryName, originBytes);
|
|
|
+ }
|
|
|
// zipFile.getName()形如: /abc/my-project.jar /abc/my-project.war /abc/my-projectzip
|
|
|
- try (FileOutputStream fos = new FileOutputStream(zipFilePath, true);
|
|
|
+ try (FileOutputStream fos = new FileOutputStream(zipFilePath, false);
|
|
|
ZipOutputStream zos = new ZipOutputStream(fos)) {
|
|
|
for (ZipEntry zipEntry : zipEntryList) {
|
|
|
- final String zipEntryName = zipEntry.getName();
|
|
|
- final byte[] originBytes = IOUtil.toBytes(zipFile.getInputStream(zipEntry));
|
|
|
- final byte[] replaceBytes = replacerMap.get(zipEntryName);
|
|
|
+ String zipEntryName = zipEntry.getName();
|
|
|
+ byte[] originBytes = originBytesMap.get(zipEntryName);
|
|
|
+ byte[] replaceBytes = replacerMap.get(zipEntryName);
|
|
|
if (replacerMap.containsKey(zipEntryName) && replaceBytes != null) {
|
|
|
// 覆盖
|
|
|
- final ZipEntry ze = new ZipEntry(zipEntryName);
|
|
|
+ ZipEntry ze = new ZipEntry(zipEntryName);
|
|
|
ze.setMethod(ZipEntry.STORED);
|
|
|
ze.setSize(replaceBytes.length);
|
|
|
ze.setCrc(IOUtil.computeCrc32(replaceBytes));
|