Merge pull request #145 from helfper/fix-zos-write-byte

Override ZipOutputStream.write(int)
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 69fc46b..7ac0164 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -166,6 +166,7 @@
 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 bd46c45..3904272 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 75acf59..a2d44ed 100644
--- a/src/main/org/apache/tools/zip/ZipOutputStream.java
+++ b/src/main/org/apache/tools/zip/ZipOutputStream.java
@@ -326,6 +326,11 @@
     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 @@
     }
 
     /**
+     * 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 5e94c19..0777630 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 @@
 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 @@
                      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();
+            }
+        }
+    }
 }