Rolling back 882798: Implementing DeflaterOutputStream.flush(). 

The change broke our Pack200 tests.

git-svn-id: https://svn.apache.org/repos/asf/harmony/enhanced/classlib/trunk@883400 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/modules/archive/src/main/java/java/util/zip/Deflater.java b/modules/archive/src/main/java/java/util/zip/Deflater.java
index 6df43e1..4c4e5bb 100644
--- a/modules/archive/src/main/java/java/util/zip/Deflater.java
+++ b/modules/archive/src/main/java/java/util/zip/Deflater.java
@@ -75,21 +75,9 @@
      */
     public static final int NO_COMPRESSION = 0;
 
-    /**
-     * Use buffering for best compression.
-     */
-    static final int Z_NO_FLUSH = 0;
+    private static final int Z_NO_FLUSH = 0;
 
-    /**
-     * Flush buffers so recipients can immediately decode the data sent thus
-     * far. This mode may degrade compression.
-     */
-    static final int Z_SYNC_FLUSH = 2;
-
-    /**
-     * Flush buffers because there is no further data.
-     */
-    static final int Z_FINISH = 4;
+    private static final int Z_FINISH = 4;
 
     // Fill in the JNI id caches
     private static native void oneTimeInitialization();
@@ -186,31 +174,24 @@
      *            maximum number of bytes of compressed data to be written.
      * @return the number of bytes of compressed data written to {@code buf}.
      */
-    public int deflate(byte[] buf, int off, int nbytes) {
-        return deflate(buf, off, nbytes, flushParm);
-    }
-
-    /**
-     * @param flushParam one of {@link #Z_NO_FLUSH}, {@link #Z_FINISH} or
-     *            {@link #Z_SYNC_FLUSH}.
-     */
-    synchronized int deflate(byte[] buf, int off, int nbytes, int flushParam) {
+    public synchronized int deflate(byte[] buf, int off, int nbytes) {
         if (streamHandle == -1) {
             throw new IllegalStateException();
         }
         // avoid int overflow, check null buf
-        if (off > buf.length || nbytes < 0 || off < 0 || buf.length - off < nbytes) {
-            throw new ArrayIndexOutOfBoundsException();
+        if (off <= buf.length && nbytes >= 0 && off >= 0
+                && buf.length - off >= nbytes) {
+            // put a stub buffer, no effect.
+            if (null == inputBuffer) {
+                setInput(STUB_INPUT_BUFFER);
+            }
+            return deflateImpl(buf, off, nbytes, streamHandle, flushParm);
         }
-        // put a stub buffer, no effect.
-        if (inputBuffer == null) {
-            setInput(STUB_INPUT_BUFFER);
-        }
-        return deflateImpl(buf, off, nbytes, streamHandle, flushParam);
+        throw new ArrayIndexOutOfBoundsException();
     }
 
     private synchronized native int deflateImpl(byte[] buf, int off,
-            int nbytes, long handle, int flushParm);
+            int nbytes, long handle, int flushParm1);
 
     private synchronized native void endImpl(long handle);
 
diff --git a/modules/archive/src/main/java/java/util/zip/DeflaterOutputStream.java b/modules/archive/src/main/java/java/util/zip/DeflaterOutputStream.java
index f091774..197426f 100644
--- a/modules/archive/src/main/java/java/util/zip/DeflaterOutputStream.java
+++ b/modules/archive/src/main/java/java/util/zip/DeflaterOutputStream.java
@@ -115,19 +115,6 @@
     }
 
     /**
-     * Writes any unwritten compressed data to the underlying stream and flushes
-     * the underlying stream.
-     *
-     * @throws IOException
-     *             If an error occurs during writing.
-     */
-    @Override public void flush() throws IOException {
-        int count = def.deflate(buf, 0, buf.length, Deflater.Z_SYNC_FLUSH);
-        out.write(buf, 0, count);
-        out.flush();
-    }
-
-    /**
      * Writes any unwritten compressed data to the underlying stream, the closes
      * all underlying streams. This stream can no longer be used after close()
      * has been called.
diff --git a/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java b/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java
index 2df354a..be28774 100644
--- a/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java
+++ b/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java
@@ -23,8 +23,6 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
 import java.util.zip.Deflater;
 import java.util.zip.DeflaterOutputStream;
 import java.util.zip.InflaterInputStream;
@@ -401,19 +399,4 @@
         assertTrue(dos.getDaflateFlag());
         dos.close();
     }
-
-    public void testFlush() throws IOException {
-        PipedOutputStream pout = new PipedOutputStream();
-        PipedInputStream pin = new PipedInputStream(pout);
-        DeflaterOutputStream out = new DeflaterOutputStream(pout);
-        InflaterInputStream in = new InflaterInputStream(pin);
-
-        out.write(1);
-        out.write(2);
-        out.write(3);
-        out.flush();
-        assertEquals(1, in.read()); // without flush, this blocks forever!!
-        assertEquals(2, in.read());
-        assertEquals(3, in.read());
-    }
 }
diff --git a/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java b/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java
index a4e3deb..fdcc3fa 100644
--- a/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java
+++ b/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java
@@ -20,13 +20,8 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
 import java.util.zip.Checksum;
-import java.util.zip.DeflaterOutputStream;
-import java.util.zip.GZIPInputStream;
 import java.util.zip.GZIPOutputStream;
-import java.util.zip.InflaterInputStream;
 
 public class GZIPOutputStreamTest extends junit.framework.TestCase {
 
@@ -163,21 +158,6 @@
 		}
 	}
 
-    public void testFlush() throws IOException {
-        PipedOutputStream pout = new PipedOutputStream();
-        PipedInputStream pin = new PipedInputStream(pout);
-        GZIPOutputStream out = new GZIPOutputStream(pout);
-        GZIPInputStream in = new GZIPInputStream(pin);
-
-        out.write(1);
-        out.write(2);
-        out.write(3);
-        out.flush();
-        assertEquals(1, in.read()); // without flush, this blocks forever!!
-        assertEquals(2, in.read());
-        assertEquals(3, in.read());
-    }
-
 	@Override
     protected void setUp() {
 	}
diff --git a/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java b/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java
index cd5dbbc..7adfeff 100644
--- a/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java
+++ b/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java
@@ -21,8 +21,6 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
 import java.util.zip.CRC32;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipException;
@@ -271,23 +269,6 @@
         zip1.close();
     }
 
-    public void testFlush() throws IOException {
-        PipedOutputStream pout = new PipedOutputStream();
-        PipedInputStream pin = new PipedInputStream(pout);
-        ZipOutputStream out = new ZipOutputStream(pout);
-        ZipInputStream in = new ZipInputStream(pin);
-        out.putNextEntry(new ZipEntry("foo.txt"));
-
-        out.write(1);
-        out.write(2);
-        out.write(3);
-        out.flush();
-        assertEquals("foo.txt", in.getNextEntry().getName());
-        assertEquals(1, in.read()); // without flush, this blocks forever!!
-        assertEquals(2, in.read());
-        assertEquals(3, in.read());
-    }
-
     @Override
     protected void setUp() throws Exception {
         super.setUp();