--- /home/cpdev/src/classpath/java/util/zip/DeflaterOutputStream.java	2005-07-02 21:03:49.000000000 +0000
+++ java/util/zip/DeflaterOutputStream.java	2005-06-30 05:34:52.000000000 +0000
@@ -82,15 +82,9 @@
     while (! def.needsInput())
       {
 	int len = def.deflate(buf, 0, buf.length);
-
-	//	System.err.println("DOS deflated " + len + " out of " + buf.length);
-	if (len <= 0)
-	  break;
-	out.write(buf, 0, len);
-      }
-
-    if (! def.needsInput())
-      throw new InternalError("Can't deflate all input?");
+	if (len > 0)
+	  out.write(buf, 0, len);
+       }
   }
 
   /** 
@@ -131,19 +125,6 @@
     def = defl;
   }
 
-  /**  
-   * Flushes the stream by calling flush() on the deflater and then
-   * on the underlying stream.  This ensures that all bytes are
-   * flushed.  This function doesn't work in Sun's JDK, but only in
-   * jazzlib.
-   */
-  public void flush() throws IOException
-  {
-    def.flush();
-    deflate();
-    out.flush();
-  }
-
   /**
    * Finishes the stream by calling finish() on the deflater.  This
    * was the only way to ensure that all bytes are flushed in Sun's
@@ -151,17 +132,14 @@
    */
   public void finish() throws IOException
   {
+    inbufWrite();
     def.finish();
     while (! def.finished())
       {
 	int len = def.deflate(buf, 0, buf.length);
-	if (len <= 0)
-	  break;
-	out.write(buf, 0, len);
+	if (len > 0)
+	  out.write(buf, 0, len);
       }
-    if (! def.finished())
-      throw new InternalError("Can't deflate all input?");
-    out.flush();
   }
 
   /**
@@ -179,9 +157,11 @@
    */
   public void write(int bval) throws IOException
   {
-    byte[] b = new byte[1];
-    b[0] = (byte) bval;
-    write(b, 0, 1);
+    if (inbuf == null)
+      inbuf = new byte[128];
+    else if (inbufLength == inbuf.length)
+      inbufWrite();
+    inbuf[inbufLength++] = (byte) bval;
   }
 
   /**
@@ -192,7 +172,23 @@
    */
   public void write(byte[] buf, int off, int len) throws IOException
   {
+    inbufWrite();
     def.setInput(buf, off, len);
     deflate();
   }
+
+  private void inbufWrite() throws IOException
+  {
+    if (inbufLength > 0)
+      {
+	int size = inbufLength;
+	inbufLength = 0;
+	write(inbuf, 0, size);
+      }
+  }
+
+  // Used, if needed, for write(int).
+  private byte[] inbuf;
+  // Used length of inbuf.
+  private int inbufLength;
 }
