[jboss-svn-commits] JBoss Common SVN: r3425 - in declarchive/trunk: impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Aug 5 00:33:54 EDT 2009


Author: ALRubinger
Date: 2009-08-05 00:33:53 -0400 (Wed, 05 Aug 2009)
New Revision: 3425

Modified:
   declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.java
   declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveFactoryTestCase.java
Log:
[EMB-32] Read bytes from the instream as if you are not a moron

Modified: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.java	2009-08-05 04:02:06 UTC (rev 3424)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.java	2009-08-05 04:33:53 UTC (rev 3425)
@@ -351,28 +351,18 @@
       final URLConnection connection = location.openConnection();
       final int length = connection.getContentLength();
       assert length > -1 : "Content length is not known";
-      byte contents[] = new byte[length];
       final InputStream in = connection.getInputStream();
-      int read = 0;
-      int currentLocation = 0;
-      int bytesToRead = 1024;
-      // Avoid ArrayIndexOutOfBounds by adjusting back the bytes we read in
-      if (bytesToRead + currentLocation > length)
+      byte[] contents = new byte[length];
+      int offset = 0;
+      while (offset < contents.length)
       {
-         bytesToRead = length;
-      }
-
-      // Read into the byte array
-      while ((read = (in.read(contents, currentLocation, bytesToRead))) > 0)
-      {
-         // Mark our new offset
-         currentLocation += read;
-
-         // Avoid ArrayIndexOutOfBounds
-         if (bytesToRead + currentLocation > length)
+         final int readLength = contents.length - offset;
+         int bytesRead = in.read(contents, offset, readLength);
+         if (bytesRead == -1)
          {
-            bytesToRead = length - currentLocation;
+            break; // EOF
          }
+         offset += bytesRead;
       }
 
       // Close up the stream

Modified: declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveFactoryTestCase.java
===================================================================
--- declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveFactoryTestCase.java	2009-08-05 04:02:06 UTC (rev 3424)
+++ declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveFactoryTestCase.java	2009-08-05 04:33:53 UTC (rev 3425)
@@ -83,6 +83,7 @@
 
       // Make an archive
       final Archive archive = VfsMemoryArchiveFactory.createVirtualArchive("testArchive.jar");
+      archive.addClass(VfsMemoryArchiveFactory.class);
       log.info("Archive: " + archive.toString(true));
 
       // Ensure exists



More information about the jboss-svn-commits mailing list