diff options
-rw-r--r-- | CONTRIBUTORS | 1 | ||||
-rw-r--r-- | contributors.xml | 4 | ||||
-rw-r--r-- | src/main/org/apache/tools/zip/ZipOutputStream.java | 18 | ||||
-rw-r--r-- | src/tests/junit/org/apache/tools/zip/ZipOutputStreamTest.java | 20 |
4 files changed, 43 insertions, 0 deletions
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 @@ -697,6 +697,10 @@ <last>Rafique</last> </name> <name> + <first>Helder</first> + <last>Pereira</last> + </name> + <name> <first>Hiroaki</first> <last>Nakamura</last> </name> 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 @@ -326,6 +326,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 * @since 1.1 @@ -902,6 +907,19 @@ public class ZipOutputStream extends FilterOutputStream { } /** + * 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. * * @param b the byte array to write 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(); + } + } + } } |