Skip to content

Commit

Permalink
Merge pull request #711 from linwumingshi/fix/invalid-entry-compresse…
Browse files Browse the repository at this point in the history
…d-size

fix: 🐛 Fix a bug when creating a Word file: invalid entry compres…
  • Loading branch information
shalousun authored Jan 25, 2024
2 parents e976269 + 9818816 commit 04b248f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/main/java/com/ly/doc/builder/WordDocBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,13 @@ public static void copyAndReplaceDocx(String content, String docxOutputPath) thr
ZipEntry entry;
while ((entry = zipInputStream.getNextEntry()) != null) {
String entryName = entry.getName();

// copy fix the bug: invalid entry compressed size
zipOutputStream.putNextEntry(new ZipEntry(entryName));
if ("word/document.xml".equals(entryName)) {
zipOutputStream.putNextEntry(new ZipEntry(entryName));
byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
zipOutputStream.write(bytes, 0, bytes.length);
} else {
// copy
zipOutputStream.putNextEntry(entry);
byte[] buffer = new byte[1024];
int len;
while ((len = zipInputStream.read(buffer)) > 0) {
Expand Down

0 comments on commit 04b248f

Please sign in to comment.