harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r724313 - in /harmony/enhanced/classlib/trunk/modules/archive/src: main/java/java/util/jar/ test/java/org/apache/harmony/archive/tests/java/util/jar/ test/java/org/apache/harmony/archive/tests/java/util/zip/
Date Mon, 08 Dec 2008 11:43:28 GMT
Author: tellison
Date: Mon Dec  8 03:43:28 2008
New Revision: 724313

URL: http://svn.apache.org/viewvc?rev=724313&view=rev
Log:
Apply patch HARMONY-6032 ([classlib][luni] Add some test cases to java.util.ZipFile and JarFile)

Modified:
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
    harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java
    harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipFileTest.java

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java?rev=724313&r1=724312&r2=724313&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
Mon Dec  8 03:43:28 2008
@@ -17,7 +17,6 @@
 
 package java.util.jar;
 
-import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FilterInputStream;
 import java.io.IOException;
@@ -255,8 +254,7 @@
             return manifest;
         }
         try {
-            ByteArrayInputStream is = (ByteArrayInputStream) super
-                    .getInputStream(manifestEntry);
+            InputStream is = super.getInputStream(manifestEntry);
             if (verifier != null) {
                 byte[] buf = new byte[is.available()];
                 is.mark(buf.length);

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java?rev=724313&r1=724312&r2=724313&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java
Mon Dec  8 03:43:28 2008
@@ -140,7 +140,7 @@
         try {
             InputStream is = new URL(jarDirUrl + "/jarlist.txt").openStream();
             while (is.available() > 0) {
-                StringBuffer linebuff = new StringBuffer(80); // Typical line
+                StringBuilder linebuff = new StringBuilder(80); // Typical line
                 // length
                 done: while (true) {
                     int nextByte = is.read();
@@ -516,4 +516,39 @@
             }
         }
     }
+    
+    /*
+     * @test JarFile.getInputStream()
+     */
+    public void testGetInputStreamLjava_util_jar_JarEntry() throws IOException {
+        Support_Resources.copyFile(resources, null, JAR1);
+        JarFile jf = new JarFile(new File(resources, JAR1));
+        InputStream is = jf.getInputStream(jf.getEntry(JAR1_ENTRY1));
+        assertTrue(is.available() > 0);
+
+        byte[] buffer = new byte[1024];
+        int r = is.read(buffer, 0, 1024);
+        jf.close();
+        is.close();
+
+        StringBuilder sb = new StringBuilder(r);
+        for (int i = 0; i < r; i++) {
+            sb.append((char) (buffer[i] & 0xff));
+        }
+        String contents = sb.toString();
+        assertTrue(contents.indexOf("foo") > 0);
+        assertTrue(contents.indexOf("bar") > 0);
+
+        try {
+            jf.getInputStream(jf.getEntry(JAR1_ENTRY1));
+            fail("should throw IllegalStateException");
+        } catch (IllegalStateException e) {
+            // Expected
+        }
+
+        jf = new JarFile(new File(resources, JAR1));
+        is = jf.getInputStream(new JarEntry("invalid"));
+        assertNull(is);
+        jf.close(); 
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipFileTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipFileTest.java?rev=724313&r1=724312&r2=724313&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipFileTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipFileTest.java
Mon Dec  8 03:43:28 2008
@@ -226,6 +226,87 @@
     public void test_size() {
         assertEquals(6, zfile.size());
     }
+    
+    /**
+     * @tests java.io.InputStream#reset()
+     */
+    public void test_reset() throws IOException {
+        // read an uncompressed entry
+        ZipEntry zentry = zfile.getEntry("File1.txt");
+        InputStream is = zfile.getInputStream(zentry);
+        byte[] rbuf1 = new byte[6];
+        byte[] rbuf2 = new byte[6];
+        int r1, r2;
+        r1 = is.read(rbuf1);
+        assertEquals(rbuf1.length, r1);
+        r2 = is.read(rbuf2);
+        assertEquals(rbuf2.length, r2);
+        
+        is.reset();
+        r2 = is.read(rbuf2);
+        assertEquals(rbuf2.length, r2);
+        is.close();
+
+        // read a compressed entry
+        byte[] rbuf3 = new byte[4185];
+        ZipEntry zentry2 = zfile.getEntry("File3.txt");
+        is = zfile.getInputStream(zentry2);
+        r1 = is.read(rbuf3);
+        assertEquals(4183, r1);
+        is.reset();
+        
+        r1 = is.read(rbuf3);
+        assertEquals(4183, r1);
+        is.close();
+
+        is = zfile.getInputStream(zentry2);
+        r1 = is.read(rbuf3, 0, 3000);
+        assertEquals(3000, r1);
+        is.reset();
+        r1 = is.read(rbuf3, 0, 3000);
+        assertEquals(3000, r1);
+        is.close();
+    }
+    
+    /**
+     * @tests java.io.InputStream#reset()
+     */
+    public void test_reset_subtest0() throws IOException {
+        // read an uncompressed entry
+        ZipEntry zentry = zfile.getEntry("File1.txt");
+        InputStream is = zfile.getInputStream(zentry);
+        byte[] rbuf1 = new byte[12];
+        byte[] rbuf2 = new byte[12];
+        int r = is.read(rbuf1, 0, 4);
+        assertEquals(4, r);
+        is.mark(0);
+        r = is.read(rbuf1);
+        assertEquals(8, r);
+        assertEquals(-1, is.read());
+        
+        is.reset();
+        r = is.read(rbuf2);
+        assertEquals(8, r);
+        assertEquals(-1, is.read());
+        is.close();
+
+        // read a compressed entry
+        byte[] rbuf3 = new byte[4185];
+        ZipEntry zentry2 = zfile.getEntry("File3.txt");
+        is = zfile.getInputStream(zentry2);
+        r = is.read(rbuf3, 0, 3000);
+        assertEquals(3000, r);
+        is.mark(0);
+        r = is.read(rbuf3);
+        assertEquals(1183, r);
+        assertEquals(-1, is.read());
+        
+        is.reset();
+        r = is.read(rbuf3);
+        assertEquals(1183, r);
+        assertEquals(-1, is.read());
+        is.close();
+    }
 
 	/**
 	 * Sets up the fixture, for example, open a network connection. This method



Mime
View raw message