harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r380999 - in /incubator/harmony/enhanced/classlib/trunk/modules/archive/src: main/java/java/util/zip/ test/java/org/apache/harmony/tests/java/util/zip/
Date Sat, 25 Feb 2006 21:36:10 GMT
Author: tellison
Date: Sat Feb 25 13:36:09 2006
New Revision: 380999

URL: http://svn.apache.org/viewcvs?rev=380999&view=rev
Log:
ZipInputStream#skip(long) should throw IAE for negative argument & use correct buffer
size.

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/ZipInputStreamTest.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipInputStream.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/AllTests.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipInputStream.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipInputStream.java?rev=380999&r1=380998&r2=380999&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipInputStream.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipInputStream.java
Sat Feb 25 13:36:09 2006
@@ -279,17 +279,20 @@
 	 * @return the number of bytes skipped
 	 */
 	public long skip(long value) throws IOException {
-		long skipped = 0;
-		int x = 0;
-		byte[] b = new byte[1024];
-		while (skipped != value) {
-			x = read(b, 0, (int) (b.length > value ? value : b.length));
-			if (x == -1)
-				return skipped;
-			skipped += x;
-		}
-		return skipped;
-	}
+		if (value >= 0) {
+			long skipped = 0;
+			byte[] b = new byte[1024];
+			while (skipped != value) {
+				long rem = value - skipped;
+				int x = read(b, 0, (int) (b.length > rem ? rem : b.length));
+				if (x == -1)
+					return skipped;
+				skipped += x;
+			}
+			return skipped;
+		} else
+			throw new IllegalArgumentException();
+}
 
 	/**
 	 * Answers 1 if the EOF has been reached, otherwise returns 0.

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/AllTests.java?rev=380999&r1=380998&r2=380999&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/AllTests.java
Sat Feb 25 13:36:09 2006
@@ -29,6 +29,7 @@
 				"Test for org.apache.harmony.tests.java.util.zip");
 		//$JUnit-BEGIN$
 		suite.addTestSuite(InflaterTest.class);
+		suite.addTestSuite(ZipInputStreamTest.class);
 		suite.addTestSuite(ZipOutputStreamTest.class);
 		//$JUnit-END$
 		return suite;

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/ZipInputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/ZipInputStreamTest.java?rev=380999&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/ZipInputStreamTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/ZipInputStreamTest.java
Sat Feb 25 13:36:09 2006
@@ -0,0 +1,64 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.util.zip;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+
+import junit.framework.TestCase;
+
+public class ZipInputStreamTest extends TestCase {
+
+	byte[] zipBytes;
+
+	byte[] dataBytes = "Some data in my file".getBytes();
+
+	public void setUp() throws IOException {
+		ByteArrayOutputStream bos = new ByteArrayOutputStream();
+		ZipOutputStream zos = new ZipOutputStream(bos);
+		ZipEntry entry = new ZipEntry("myFile");
+		zos.putNextEntry(entry);
+		zos.write(dataBytes);
+		zos.closeEntry();
+		zos.close();
+		zipBytes = bos.toByteArray();
+	}
+
+	/**
+	 * @tests java.util.zip.ZipInputStream#skip(long)
+	 */
+	public void test_skipJ() throws IOException {
+		ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(
+				zipBytes));
+		zis.getNextEntry();
+		long skipLen = dataBytes.length / 2;
+		assertEquals("Assert 0: failed valid skip", skipLen, zis.skip(skipLen));
+		zis.skip(dataBytes.length);
+		assertEquals("Assert 1: performed invalid skip", 0, zis.skip(1));
+		assertEquals("Assert 2: failed zero len skip", 0, zis.skip(0));
+		try {
+			zis.skip(-1);
+			fail("Assert 3: Expected Illegal argument exception");
+		} catch (IllegalArgumentException e) {
+			// Expected
+		}
+	}
+
+}



Mime
View raw message