diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 69fc46bb4..7ac01649d 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -166,6 +166,7 @@ Grégoire Vatry Günther Kögel Harish Prabandham Haroon Rafique +Helder Pereira Hiroaki Nakamura Holger Engels Holger Joest diff --git a/contributors.xml b/contributors.xml index bd46c455f..3904272ac 100644 --- a/contributors.xml +++ b/contributors.xml @@ -696,6 +696,10 @@ Haroon Rafique + + Helder + Pereira + Hiroaki Nakamura diff --git a/src/main/org/apache/tools/zip/ZipOutputStream.java b/src/main/org/apache/tools/zip/ZipOutputStream.java index 75acf5927..a2d44edaf 100644 --- a/src/main/org/apache/tools/zip/ZipOutputStream.java +++ b/src/main/org/apache/tools/zip/ZipOutputStream.java @@ -325,6 +325,11 @@ public class ZipOutputStream extends FilterOutputStream { private final Calendar calendarInstance = Calendar.getInstance(); + /** + * Temporary buffer used for the {@link #write(int)} method. + */ + private final byte[] oneByte = new byte[1]; + /** * Creates a new ZIP OutputStream filtering the underlying stream. * @param out the outputstream to zip @@ -901,6 +906,19 @@ public class ZipOutputStream extends FilterOutputStream { return ZipUtil.canHandleEntryData(ae); } + /** + * Writes a byte to ZIP entry. + * + * @param b the byte to write + * @throws IOException on error + * @since Ant 1.10.10 + */ + @Override + public void write(int b) throws IOException { + oneByte[0] = (byte) (b & 0xff); + write(oneByte, 0, 1); + } + /** * Writes bytes to ZIP entry. * diff --git a/src/tests/junit/org/apache/tools/zip/ZipOutputStreamTest.java b/src/tests/junit/org/apache/tools/zip/ZipOutputStreamTest.java index 5e94c1916..0777630bd 100644 --- a/src/tests/junit/org/apache/tools/zip/ZipOutputStreamTest.java +++ b/src/tests/junit/org/apache/tools/zip/ZipOutputStreamTest.java @@ -21,8 +21,14 @@ package org.apache.tools.zip; import org.junit.Before; import org.junit.Test; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.util.Calendar; import java.util.Date; +import java.util.jar.JarFile; +import java.util.jar.Manifest; +import java.util.zip.ZipInputStream; import static org.junit.Assert.assertEquals; @@ -70,4 +76,18 @@ public class ZipOutputStreamTest { ZipUtil.adjustToLong(2 * Integer.MAX_VALUE)); } + @Test + public void testWriteAndReadManifest() throws IOException { + try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + try (ZipOutputStream zos = new ZipOutputStream(baos)) { + zos.putNextEntry(new ZipEntry(JarFile.MANIFEST_NAME)); + new Manifest().write(zos); + } + try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ZipInputStream zis = new ZipInputStream(bais)) { + zis.getNextEntry(); + zis.closeEntry(); + } + } + } }