harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r499712 - in /harmony/enhanced/classlib/trunk/modules/archive/src: main/java/java/util/zip/ test/java/org/apache/harmony/archive/tests/java/util/zip/
Date Thu, 25 Jan 2007 09:43:02 GMT
Author: pyang
Date: Thu Jan 25 01:42:56 2007
New Revision: 499712

URL: http://svn.apache.org/viewvc?view=rev&rev=499712
Log:
Apply patch for HARMONY-2427( [classlib][archive] [compatibility] Harmony checks correctness
of java.util.zip.GZIPInputStream.read(BII) arguments even if EOF was reached but RI returns
-1)

Modified:
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/GZIPInputStream.java
    harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java
    harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/GZIPInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/GZIPInputStream.java?view=diff&rev=499712&r1=499711&r2=499712
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/GZIPInputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/GZIPInputStream.java
Thu Jan 25 01:42:56 2007
@@ -133,6 +133,12 @@
 	 */
 	@Override
     public int read(byte[] buffer, int off, int nbytes) throws IOException {
+        if (closed) {
+            throw new IOException(Messages.getString("archive.1E")); //$NON-NLS-1$
+        }
+        if(eof){
+            return -1;
+        }
 		// avoid int overflow, check null buffer
 		if (off <= buffer.length && nbytes >= 0 && off >= 0
 				&& buffer.length - off >= nbytes) {

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java?view=diff&rev=499712&r1=499711&r2=499712
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java
Thu Jan 25 01:42:56 2007
@@ -99,104 +99,120 @@
 	/**
 	 * @tests java.util.zip.GZIPInputStream#read(byte[], int, int)
 	 */
-	public void test_read$BII() {
+	public void test_read$BII() throws IOException {
 		// test method java.util.zip.GZIPInputStream.readBII
-		byte orgBuf[] = { '3', '5', '2', 'r', 'g', 'e', 'f', 'd', 'e', 'w' };
-		byte outBuf[] = new byte[100];
-		try {
-			int result = 0;
-			Support_Resources.copyFile(resources, "GZIPInputStream",
-					"hyts_gInput.txt.gz");
-			String resPath = resources.toString();
-			if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\') {
-                resPath = resPath.substring(1);
-            }
-			final URL gInput = new URL("file:/" + resPath
-					+ "/GZIPInputStream/hyts_gInput.txt.gz");
-			TestGZIPInputStream inGZIP = new TestGZIPInputStream(gInput
-					.openConnection().getInputStream());
-			while (!(inGZIP.endofInput())) {
-				result += inGZIP.read(outBuf, result, outBuf.length - result);
-			}
-			assertEquals("the checkSum value of the compressed and decompressed data does not equal",
-					2074883667L, inGZIP.getChecksum().getValue());
-			for (int i = 0; i < orgBuf.length; i++) {
-				assertTrue(
-						"the decompressed data does not equal the original data decompressed",
-						orgBuf[i] == outBuf[i]);
-				// System.out.println(orgBuf[i] + " " + outBuf[i]);
-			}
-			int r = 0;
-			try {
-				inGZIP.read(outBuf, 100, 1);
-			} catch (ArrayIndexOutOfBoundsException e) {
-				r = 1;
-			}
-			inGZIP.close();
-			assertEquals("Boundary Check was not present", 1, r);
-		} catch (IOException e) {
-			e.printStackTrace();
-			fail("unexpected: " + e);
-		}
+        byte orgBuf[] = { '3', '5', '2', 'r', 'g', 'e', 'f', 'd', 'e', 'w' };
+        byte outBuf[] = new byte[100];
+        int result = 0;
+        Support_Resources.copyFile(resources, "GZIPInputStream",
+                "hyts_gInput.txt.gz");
+        String resPath = resources.toString();
+        if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\') {
+            resPath = resPath.substring(1);
+        }
+        final URL gInput = new URL("file:/" + resPath
+                + "/GZIPInputStream/hyts_gInput.txt.gz");
+        TestGZIPInputStream inGZIP = new TestGZIPInputStream(gInput
+                .openConnection().getInputStream());
+        while (!(inGZIP.endofInput())) {
+            result += inGZIP.read(outBuf, result, outBuf.length - result);
+        }
+        assertEquals(
+                "the checkSum value of the compressed and decompressed data does not equal",
+                2074883667L, inGZIP.getChecksum().getValue());
+        for (int i = 0; i < orgBuf.length; i++) {
+            assertTrue(
+                    "the decompressed data does not equal the original data decompressed",
+                    orgBuf[i] == outBuf[i]);
+            // System.out.println(orgBuf[i] + " " + outBuf[i]);
+        }
+        int r = 0;
+        try {
+            inGZIP.read(outBuf, 100, 1);
+        } catch (IndexOutOfBoundsException e) {
+            r = 1;
+        }
+        inGZIP.close();
+        // line below fails on RI also, comment out.
+        // assertEquals("Boundary Check was not present", 1, r);
 
-		try {
-			// Create compressed data which is exactly 512 bytes (after the
-			// header),
-			// the size of the InflaterStream internal buffer
-			byte[] test = new byte[507];
-			for (int i = 0; i < 256; i++) {
-                test[i] = (byte) i;
-            }
-			for (int i = 256; i < test.length; i++) {
-                test[i] = (byte) (256 - i);
-            }
-			ByteArrayOutputStream bout = new ByteArrayOutputStream();
-			GZIPOutputStream out = new GZIPOutputStream(bout);
-			out.write(test);
-			out.close();
-			byte[] comp = bout.toByteArray();
-			GZIPInputStream gin2 = new GZIPInputStream(
-					new ByteArrayInputStream(comp), 512);
-			int result, total = 0;
-			while ((result = gin2.read(test)) != -1) {
-                total += result;
-            }
-			assertEquals("Should return -1", -1, gin2.read());
-			gin2.close();
-			assertTrue("Incorrectly decompressed", total == test.length);
+        // Create compressed data which is exactly 512 bytes (after the
+        // header),
+        // the size of the InflaterStream internal buffer
+        byte[] test = new byte[507];
+        for (int i = 0; i < 256; i++) {
+            test[i] = (byte) i;
+        }
+        for (int i = 256; i < test.length; i++) {
+            test[i] = (byte) (256 - i);
+        }
+        ByteArrayOutputStream bout = new ByteArrayOutputStream();
+        GZIPOutputStream out = new GZIPOutputStream(bout);
+        out.write(test);
+        out.close();
+        byte[] comp = bout.toByteArray();
+        GZIPInputStream gin2 = new GZIPInputStream(new ByteArrayInputStream(
+                comp), 512);
+        int total = 0;
+        while ((result = gin2.read(test)) != -1) {
+            total += result;
+        }
+        assertEquals("Should return -1", -1, gin2.read());
+        gin2.close();
+        assertTrue("Incorrectly decompressed", total == test.length);
 
-			gin2 = new GZIPInputStream(new ByteArrayInputStream(comp), 512);
-			total = 0;
-			while ((result = gin2.read(new byte[200])) != -1) {
-				total += result;
-			}
-			assertEquals("Should return -1", -1, gin2.read());
-			gin2.close();
-			assertTrue("Incorrectly decompressed", total == test.length);
+        gin2 = new GZIPInputStream(new ByteArrayInputStream(comp), 512);
+        total = 0;
+        while ((result = gin2.read(new byte[200])) != -1) {
+            total += result;
+        }
+        assertEquals("Should return -1", -1, gin2.read());
+        gin2.close();
+        assertTrue("Incorrectly decompressed", total == test.length);
 
-			gin2 = new GZIPInputStream(new ByteArrayInputStream(comp), 516);
-			total = 0;
-			while ((result = gin2.read(new byte[200])) != -1) {
-				total += result;
-			}
-			assertEquals("Should return -1", -1, gin2.read());
-			gin2.close();
-			assertTrue("Incorrectly decompressed", total == test.length);
+        gin2 = new GZIPInputStream(new ByteArrayInputStream(comp), 516);
+        total = 0;
+        while ((result = gin2.read(new byte[200])) != -1) {
+            total += result;
+        }
+        assertEquals("Should return -1", -1, gin2.read());
+        gin2.close();
+        assertTrue("Incorrectly decompressed", total == test.length);
 
-			comp[40] = 0;
-			gin2 = new GZIPInputStream(new ByteArrayInputStream(comp), 512);
-			boolean exception = false;
-			try {
-				while (gin2.read(test) != -1) {
-                    ;
-                }
-			} catch (IOException e) {
-				exception = true;
-			}
-			assertTrue("Exception expected", exception);
-		} catch (IOException e) {
-			fail("Unexpected: " + e);
-		}
+        comp[40] = 0;
+        gin2 = new GZIPInputStream(new ByteArrayInputStream(comp), 512);
+        boolean exception = false;
+        try {
+            while (gin2.read(test) != -1) {
+                ;
+            }
+        } catch (IOException e) {
+            exception = true;
+        }
+        assertTrue("Exception expected", exception);
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        GZIPOutputStream zipout = new GZIPOutputStream(baos);
+        zipout.write(test);
+        zipout.close();
+        outBuf = new byte[530];
+        GZIPInputStream in= new GZIPInputStream(new ByteArrayInputStream(baos.toByteArray()));
+        try {
+            in.read(outBuf, 530, 1);
+            fail("Test failed IOOBE was not thrown");
+        } catch (IndexOutOfBoundsException e) {
+        }
+        while (true) {
+            result = in.read(outBuf, 0, 5);
+            if (result == -1) {
+                //"EOF was reached";
+                break;
+            }
+        }
+        result = -10;
+        result = in.read(null, 100, 1);
+        result = in.read(outBuf, -100, 1);
+        result = in.read(outBuf, -1, 1);// 100, 1);
 	}
 
 	/**

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java?view=diff&rev=499712&r1=499711&r2=499712
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java
Thu Jan 25 01:42:56 2007
@@ -17,8 +17,11 @@
 package org.apache.harmony.archive.tests.java.util.zip;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.zip.DeflaterOutputStream;
 import java.util.zip.Inflater;
 import java.util.zip.InflaterInputStream;
 
@@ -158,8 +161,35 @@
 	/**
 	 * @tests java.util.zip.InflaterInputStream#read(byte[], int, int)
 	 */
-	public void test_read$BII() {
-		// TODO
+	public void test_read$BII() throws IOException{
+        byte[] test = new byte[507];
+        for (int i = 0; i < 256; i++) {
+            test[i] = (byte) i;
+        }
+        for (int i = 256; i < test.length; i++) {
+            test[i] = (byte) (256 - i);
+        }
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        DeflaterOutputStream dos = new DeflaterOutputStream(baos);
+        dos.write(test);
+        dos.close();
+        InputStream is = new ByteArrayInputStream(baos.toByteArray());
+        InflaterInputStream iis = new InflaterInputStream(is);
+        byte[] outBuf = new byte[530];
+        int result = 0;
+        while (true) {
+            result = iis.read(outBuf, 0, 5);
+            if (result == -1) {
+                //"EOF was reached";
+                break;
+            }
+        }
+        try {
+            iis.read(outBuf, -1, 10);
+            fail("should throw IOOBE.");
+        } catch (IndexOutOfBoundsException e) {
+            // expected;
+        }
 	}
 
     /**



Mime
View raw message