harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r539473 - in /harmony/enhanced/classlib/trunk/modules/archive/src: main/java/java/util/zip/GZIPInputStream.java test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java
Date Fri, 18 May 2007 14:04:23 GMT
Author: ayza
Date: Fri May 18 07:04:18 2007
New Revision: 539473

URL: http://svn.apache.org/viewvc?view=rev&rev=539473
Log:
Applying another patch from HARMONY-3703 ( [classlib][archive][netbeans] GZIPInputStream throws
IOException when feeding from the network)

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

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=539473&r1=539472&r2=539473
==============================================================================
--- 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
Fri May 18 07:04:18 2007
@@ -149,13 +149,12 @@
 				eos = true;
 				// Get non-compressed bytes read by fill
 				int size = inf.getRemaining();
-				byte[] b = new byte[8];
+				final int trailerSize = 8; // crc (4 bytes) + total out (4 bytes)
+				byte[] b = new byte[trailerSize];
+				int copySize = (size > trailerSize) ? trailerSize : size;
 
-				if (size > b.length) {
-					size = b.length;
-				}
-				System.arraycopy(buf, len - size, b, 0, size);
-				readFully(b, size, b.length - size);
+                System.arraycopy(buf, len - size, b, 0, copySize);
+				readFully(b, copySize, trailerSize - copySize);
 
 				if (getLong(b, 0) != crc.getValue()) {
                     throw new IOException(Messages.getString("archive.20")); //$NON-NLS-1$

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=539473&r1=539472&r2=539473
==============================================================================
--- 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
Fri May 18 07:04:18 2007
@@ -19,6 +19,8 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -252,6 +254,35 @@
 			fail("unexpected: " + e);
 		}
 	}
+
+    /**
+     * Regression test for HARMONY-3703.
+     * @tests java.util.zip.GZIPInputStream#read()
+     */
+    public void test_read() throws IOException {
+        GZIPInputStream gis = null;
+        int result = 0;
+        byte[] buffer = new byte[] {1,2,3,4,5,6,7,8,9,10};
+        File f = new File(resources.getAbsolutePath() + "test.gz");
+        FileOutputStream out = new FileOutputStream(f);
+        GZIPOutputStream gout = new GZIPOutputStream(out);
+
+        // write 100 bytes to the stream
+        for(int i = 0; i < 10; i++) {
+            gout.write(buffer);
+        }
+        gout.finish();
+        out.write(1);
+        out.close();
+
+        gis = new GZIPInputStream(new FileInputStream(f));
+        buffer = new byte[100];
+        gis.read(buffer);
+        result = gis.read();
+        gis.close();
+
+        assertEquals("Incorrect value returned at the end of the file", -1, result);
+    }
 
 	@Override
     protected void setUp() {



Mime
View raw message