From bf8a8cf657cade4f4d3102ee6af4db3dd4162077 Mon Sep 17 00:00:00 2001 From: Iyxan23 Date: Fri, 17 May 2024 21:08:21 +0700 Subject: [PATCH] fix: null bytes appended on files with no misaligns (closes #11) Credits to @deroko --- src/main/java/com/iyxan23/zipalignjava/ZipAlign.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/iyxan23/zipalignjava/ZipAlign.java b/src/main/java/com/iyxan23/zipalignjava/ZipAlign.java index 48fb0c5..7ad9dbf 100644 --- a/src/main/java/com/iyxan23/zipalignjava/ZipAlign.java +++ b/src/main/java/com/iyxan23/zipalignjava/ZipAlign.java @@ -293,7 +293,10 @@ public static void alignZip(RandomAccessFile file, OutputStream out, int alignme if (neededAlignments.size() == 0) { // there is no needed alignment, stream it all! byte[] buffer = new byte[8192]; - while (file.read(buffer) != -1) out.write(buffer); + int len; + while (-1 != (len = file.read(buffer))){ + out.write(buffer, 0, len); + } return; }