--- /home/cpdev/src/classpath/java/util/zip/GZIPOutputStream.java	2005-07-02 21:03:49.000000000 +0000
+++ java/util/zip/GZIPOutputStream.java	2005-06-30 05:34:52.000000000 +0000
@@ -82,32 +82,28 @@
   {
     super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true), size);
     crc = new CRC32();
-    int mod_time = (int) (System.currentTimeMillis() / 1000L);
-    byte[] gzipHeader =
-      {
-	/* The two magic bytes */
-	(byte) GZIPInputStream.GZIP_MAGIC,
-	(byte) (GZIPInputStream.GZIP_MAGIC >> 8),
-	  
-	/* The compression type */
-	(byte) Deflater.DEFLATED,
-	
-        /* The flags (not set) */
-	0,
-	
-	/* The modification time */
-	(byte) mod_time, (byte) (mod_time >> 8), 
-	(byte) (mod_time >> 16), (byte) (mod_time >> 24), 
-
-	/* The extra flags */
-	0,
-    
-	/* The OS type (unknown) */
-	(byte) 255
-      };
+    put2(GZIPInputStream.GZIP_MAGIC);
+    out.write(GZIPInputStream.Z_DEFLATED);
+    // No flags for now.
+    out.write(0);
+    // No time either.
+    put2(0);
+    put2(0);
+    // No xflags either.
+    out.write(0);
+    // FIXME: unknown OS.
+    out.write(255);
+  }
 
-    out.write(gzipHeader);
-    //    System.err.println("wrote GZIP header (" + gzipHeader.length + " bytes )");
+  public synchronized void write(int bval) throws IOException
+  {
+    super.write(bval);
+    crc.update(bval);
+  }
+
+  public synchronized void write(byte[] buf) throws IOException
+  {
+    write(buf, 0, buf.length);
   }
 
   public synchronized void write(byte[] buf, int off, int len)
@@ -130,22 +126,21 @@
   public void finish() throws IOException
   {
     super.finish();
+    put4((int) crc.getValue());
+    put4(def.getTotalIn());
+  }
 
-    int totalin = def.getTotalIn();
-    int crcval = (int) (crc.getValue() & 0xffffffff);
-
-    //    System.err.println("CRC val is " + Integer.toHexString( crcval ) 		       + " and length " + Integer.toHexString(totalin));
-    
-    byte[] gzipFooter = 
-      {
-	(byte) crcval, (byte) (crcval >> 8),
-	(byte) (crcval >> 16), (byte) (crcval >> 24),
-
-	(byte) totalin, (byte) (totalin >> 8),
-	(byte) (totalin >> 16), (byte) (totalin >> 24)
-      };
+  private final void put2(int i) throws IOException
+  {
+    out.write(i);
+    out.write(i >> 8);
+  }
 
-    out.write(gzipFooter);
-  //    System.err.println("wrote GZIP trailer (" + gzipFooter.length + " bytes )");    
+  private final void put4 (int i) throws IOException
+  {
+    out.write(i);
+    out.write(i >> 8);
+    out.write(i >> 16);
+    out.write(i >> 24);
   }
 }
