This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: PR 7766


Here's a possible patch and test case for PR 7766:

--- ZipInputStream.java 15 Jun 2002 18:31:13 -0000      1.14
+++ ZipInputStream.java 31 Aug 2002 09:25:59 -0000
@@ -61,6 +61,7 @@
   private int method;
   private int flags;
   private int avail;
+  private boolean entryAtEOF;
 
   /**
    * Creates a new Zip input stream, reading a zip archive.
@@ -171,6 +172,7 @@
     String name = new String(buffer);
     
     entry = createZipEntry(name);
+    entryAtEOF = false;
     entry.setMethod(method);
     if ((flags & 8) == 0)
       {
@@ -252,11 +254,12 @@
     if (method == ZipOutputStream.DEFLATED)
       inf.reset();
     entry = null;
+    entryAtEOF = true;
   }
 
   public int available() throws IOException
   {
-    return entry != null ? 1 : 0;
+    return entryAtEOF ? 0 : 1;
   }
 
   /**
@@ -335,6 +338,7 @@
          throw new ZipException("CRC mismatch");
        crc.reset();
        entry = null;
+        entryAtEOF = true;
       }
     return len;
   }

; cat ZISEOFTest.java
import java.net.URL;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class ZISEOFTest {
    private static boolean pass = true;

    private static void check(boolean b, String s) {
        if (!b) {
            System.out.println("ERROR: " + s);
            pass = false;
        }
    }

    public static void main(String[] s) throws Exception {
        URL u = new URL("http://www.xwt.org/dist/xwt-0258.jar";);
        ZipInputStream zis = new ZipInputStream(u.openStream());

        check(zis.available() > 0, "Initially unavailable");

        for (ZipEntry ze; (ze = zis.getNextEntry()) != null; ) {
            check(zis.available() > 0, "Initially unavailable");

            // System.out.println(ze.toString());

            byte[] b = new byte[1];
            int bytesRead;
            while (zis.available() > 0) {
                bytesRead = zis.read(b, 0, b.length);
                if (bytesRead == -1)
                    check(zis.available() == 0, "Still available after EOF");
            }

            check((bytesRead = zis.read(b, 0, b.length)) == -1,
                  "Unexpected read success: bytesRead=" + bytesRead);
        }

        System.out.println(pass ? "PASS" : "FAIL");
    }
}

; java ZISEOFTest
PASS

Before patch
; gij ZISEOFTest
ERROR: Initially unavailable
FAIL

After patch
; gij ZISEOFTest
PASS


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]