Author: bodewig
Date: Thu Aug  4 09:07:34 2011
New Revision: 1153795

URL: http://svn.apache.org/viewvc?rev=1153795&view=rev
Log:
On second, third and forth thought, this already is all that is needed to make 
ZipFile work.  The Java7 JAR interop test fails, looking into it.  COMPRESS-149

Modified:
    
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java?rev=1153795&r1=1153794&r2=1153795&view=diff
==============================================================================
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java
 Thu Aug  4 09:07:34 2011
@@ -34,8 +34,10 @@ import org.junit.Ignore;
 import org.junit.Test;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assume.assumeNotNull;
 import static org.junit.Assume.assumeTrue;
 
@@ -82,6 +84,24 @@ public class Zip64SupportTest {
         read100KFilesImpl(get100KFileFileGeneratedByJava7Jar());
     }
 
+    @Test public void read5GBOfZerosUsingZipFile() throws Throwable {
+        read5GBOfZerosUsingZipFileImpl(get5GBZerosFile(), "5GB_of_Zeros");
+    }
+
+    @Test public void read5GBOfZerosGeneratedBy7ZIPUsingZipFile()
+        throws Throwable {
+        read5GBOfZerosUsingZipFileImpl(get5GBZerosFileGeneratedBy7ZIP(),
+                                       "5GB_of_Zeros");
+    }
+
+    @Ignore
+    @Test public void read5GBOfZerosGeneratedByJava7JarUsingZipFile()
+        throws Throwable {
+        read5GBOfZerosUsingZipFileImpl(get5GBZerosFileGeneratedByJava7Jar(),
+                                       "5GB_of_Zeros");
+    }
+
+    @Ignore
     @Test public void read100KFilesUsingZipFile() throws Throwable {
         read100KFilesUsingZipFileImpl(get100KFileFile());
     }
@@ -1429,6 +1449,42 @@ public class Zip64SupportTest {
         }
     }
 
+    private static void read5GBOfZerosUsingZipFileImpl(File f,
+                                                       String expectedName)
+        throws IOException {
+        ZipFile zf = null;
+        try {
+            zf = new ZipFile(f);
+            Enumeration e = zf.getEntries();
+            assertTrue(e.hasMoreElements());
+            ZipArchiveEntry zae = (ZipArchiveEntry) e.nextElement();
+            assertEquals(expectedName, zae.getName());
+            assertEquals(FIVE_BILLION, zae.getSize());
+            byte[] buf = new byte[1024 * 1024];
+            long read = 0;
+            Random r = new Random(System.currentTimeMillis());
+            int readNow;
+            InputStream zin = zf.getInputStream(zae);
+            try {
+                while ((readNow = zin.read(buf, 0, buf.length)) > 0) {
+                    // testing all bytes for a value of 0 is going to take
+                    // too long, just pick a few ones randomly
+                    for (int i = 0; i < 1024; i++) {
+                        int idx = r.nextInt(readNow);
+                        assertEquals("testing byte " + (read + idx), 0, 
buf[idx]);
+                    }
+                    read += readNow;
+                }
+            } finally {
+                zin.close();
+            }
+            assertEquals(FIVE_BILLION, read);
+            assertFalse(e.hasMoreElements());
+        } finally {
+            ZipFile.closeQuietly(zf);
+        }
+    }
+
     private static void read100KFilesImpl(File f) throws IOException {
         FileInputStream fin = new FileInputStream(f);
         ZipArchiveInputStream zin = null;


Reply via email to