You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2010/07/27 09:44:55 UTC

svn commit: r979566 - /felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java

Author: clement
Date: Tue Jul 27 07:44:55 2010
New Revision: 979566

URL: http://svn.apache.org/viewvc?rev=979566&view=rev
Log:
FELIX-2485 Improve the performance of the manipulator on large files
Now we use a buffered copy instead of byte-based copy. The difference is notable moslty on huge file, like native libraries.

Modified:
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java

Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java?rev=979566&r1=979565&r2=979566&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java (original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java Tue Jul 27 07:44:55 2010
@@ -326,6 +326,19 @@ public class Pojoization {
             }
         }
     }
+    
+    /**
+     * Copies an input stream into an output stream but does not close the streams.
+     * @param in the input stream
+     * @param out the output stream
+     * @throws IOException if the stream cannot be copied
+     */
+    private static void copyStreamWithoutClosing(InputStream in, OutputStream out) throws IOException {
+        byte[] b = new byte[4096];
+        for (int n; (n = in.read(b)) != -1;) {
+            out.write(b, 0, n);
+        }
+    }
 
     /**
      * Manipulate the input bundle.
@@ -368,12 +381,8 @@ public class Pojoization {
                     } else { // The class is already manipulated
                         jos.putNextEntry(curEntry);
                         InputStream currIn = m_inputJar.getInputStream(curEntry);
-                        int c;
-                        int i = 0;
-                        while ((c = currIn.read()) >= 0) {
-                            jos.write(c);
-                            i++;
-                        }
+                        copyStreamWithoutClosing(currIn, jos);
+                        
                         currIn.close();
                         jos.closeEntry();
                     }
@@ -383,12 +392,7 @@ public class Pojoization {
                         // copy the entry header to jos
                         jos.putNextEntry(curEntry);
                         InputStream currIn = m_inputJar.getInputStream(curEntry);
-                        int c;
-                        int i = 0;
-                        while ((c = currIn.read()) >= 0) {
-                            jos.write(c);
-                            i++;
-                        }
+                        copyStreamWithoutClosing(currIn, jos);
                         currIn.close();
                         jos.closeEntry();
                     }