commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kohs...@apache.org
Subject svn commit: r360306 - in /jakarta/commons/sandbox/javaflow/trunk: ./ src/java/org/apache/commons/javaflow/utils/ src/test/ src/test/org/apache/commons/javaflow/ src/test/org/apache/commons/javaflow/flow/
Date Sat, 31 Dec 2005 15:52:52 GMT
Author: kohsuke
Date: Sat Dec 31 07:52:45 2005
New Revision: 360306

URL: http://svn.apache.org/viewcvs?rev=360306&view=rev
Log:
removed commons-io dependency to make the footprint smaller

Modified:
    jakarta/commons/sandbox/javaflow/trunk/project.properties
    jakarta/commons/sandbox/javaflow/trunk/project.xml
    jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/RewritingUtils.java
    jakarta/commons/sandbox/javaflow/trunk/src/test/RewriteTool.java
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/TestClassLoader.java
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/flow/NullVariableMethodFlow.java

Modified: jakarta/commons/sandbox/javaflow/trunk/project.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/project.properties?rev=360306&r1=360305&r2=360306&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/project.properties (original)
+++ jakarta/commons/sandbox/javaflow/trunk/project.properties Sat Dec 31 07:52:45 2005
@@ -34,5 +34,4 @@
 # ------------------------------------------------------------------------
 maven.jar.commons-jci = lib/commons-jci-r291284.jar
 maven.jar.bcel = lib/jakarta-bcel-20050813.jar
-maven.jar.commons-io = lib/commons-io-20050621.133116.jar
 maven.jar.asm-all = lib/asm-all-2.2.1.jar

Modified: jakarta/commons/sandbox/javaflow/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/project.xml?rev=360306&r1=360305&r2=360306&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/project.xml (original)
+++ jakarta/commons/sandbox/javaflow/trunk/project.xml Sat Dec 31 07:52:45 2005
@@ -100,6 +100,12 @@
   </contributors>
 
   <dependencies>
+    <!-- runtime dependencies -->
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging-api</artifactId>
+      <version>1.0.4</version>
+    </dependency>
     <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
@@ -113,12 +119,21 @@
       <type>jar</type>
     </dependency>
     <dependency>
+      <groupId>asm</groupId>
+      <artifactId>asm-all</artifactId>
+      <version>2.2.1</version>
+      <jar>${basedir}/lib/asm-all-2.2.1.jar</jar>
+      <type>jar</type>
+    </dependency>
+    <!-- optional runtime dependency -->
+    <dependency>
       <groupId>commons-jci</groupId>
       <artifactId>commons-jci</artifactId>
       <version>r291284</version>
       <jar>${basedir}/lib/commons-jci-r291284.jar</jar>
       <type>jar</type>
     </dependency>
+    <!-- build/test dependencies -->
     <dependency>
       <groupId>ant</groupId>
       <artifactId>ant</artifactId>
@@ -138,23 +153,6 @@
       <groupId>xstream</groupId>
       <artifactId>xstream</artifactId>
       <version>1.1</version>
-    </dependency>
-    <dependency>
-      <groupId>commons-logging</groupId>
-      <artifactId>commons-logging-api</artifactId>
-      <version>1.0.4</version>
-    </dependency>
-    <dependency>
-      <groupId>commons-io</groupId>
-      <artifactId>commons-io</artifactId>
-      <version>20050621.133116</version>
-    </dependency>
-    <dependency>
-      <groupId>asm</groupId>
-      <artifactId>asm-all</artifactId>
-      <version>2.2.1</version>
-      <jar>${basedir}/lib/asm-all-2.2.1.jar</jar>
-      <type>jar</type>
     </dependency>
   </dependencies>
 

Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/RewritingUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/RewritingUtils.java?rev=360306&r1=360305&r2=360306&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/RewritingUtils.java
(original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/RewritingUtils.java
Sat Dec 31 07:52:45 2005
@@ -15,21 +15,22 @@
  */
 package org.apache.commons.javaflow.utils;
 
-import java.io.ByteArrayInputStream;
+import org.apache.commons.javaflow.bytecode.transformation.ResourceTransformer;
+import org.apache.commons.javaflow.bytecode.transformation.bcel.BcelClassTransformer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.jar.JarEntry;
 import java.util.jar.JarInputStream;
 import java.util.jar.JarOutputStream;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.javaflow.bytecode.transformation.ResourceTransformer;
-import org.apache.commons.javaflow.bytecode.transformation.bcel.BcelClassTransformer;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 public final class RewritingUtils {
 
@@ -54,7 +55,7 @@
             final File pOutput
             ) throws IOException {
 
-        final byte[] original = FileUtils.readFileToByteArray(pInput);
+        final byte[] original = toByteArray(pInput);
         byte[] transformed = transformer.transform(original);
         final FileOutputStream os = new FileOutputStream(pOutput);
         os.write(transformed);
@@ -101,11 +102,11 @@
                         log.debug("transforming " + name);
                     }
 
-                    final byte[] original = IOUtils.toByteArray(pInput);
+                    final byte[] original = toByteArray(pInput);
 
                     byte[] transformed = transformer.transform(original);
 
-                    IOUtils.copy(new ByteArrayInputStream(transformed), pOutput);
+                    pOutput.write(transformed);
 
                     changed |= transformed.length != original.length;
 
@@ -126,10 +127,9 @@
                 continue;
             }
 
-            final byte[] original = IOUtils.toByteArray(pInput);
-            IOUtils.copy(new ByteArrayInputStream(original), pOutput);
+            int length = copy(pInput,pOutput);
 
-            log.debug("copied " + name + "(" + original.length + ")");
+            log.debug("copied " + name + "(" + length + ")");
         }
 
         pInput.close();
@@ -138,6 +138,39 @@
         return changed;
     }
 
+    public static byte[] toByteArray(File f) throws IOException {
+        InputStream in = new FileInputStream(f);
+        try {
+            return toByteArray(in);
+        } finally {
+            in.close();
+        }
+    }
+
+    public static byte[] toByteArray(InputStream in) throws IOException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        copy(in,baos);
+        return baos.toByteArray();
+    }
+
+    /**
+     * Copies the entire {@link InputStream} to the given {@link OutputStream}.
+     *
+     * @return
+     *      the number of bytes copied.
+     */
+    public static int copy(InputStream in, OutputStream out) throws IOException {
+        byte[] buf = new byte[8192];
+        int n;
+        int total = 0;
+        while ((n = in.read(buf)) >= 0) {
+            out.write(buf, 0, n);
+            total += n;
+        }
+        return total;
+    }
+
+
     public static void main(final String[] args) throws FileNotFoundException, IOException
{
         ResourceTransformer transformer = new BcelClassTransformer();
 
@@ -154,5 +187,4 @@
         System.out.println("done");
         
     }
-    
 }

Modified: jakarta/commons/sandbox/javaflow/trunk/src/test/RewriteTool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/RewriteTool.java?rev=360306&r1=360305&r2=360306&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/RewriteTool.java (original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/RewriteTool.java Sat Dec 31 07:52:45 2005
@@ -16,7 +16,7 @@
 import org.apache.commons.javaflow.bytecode.transformation.ResourceTransformer;
 import org.apache.commons.javaflow.bytecode.transformation.asm.AsmClassTransformer;
 import org.apache.commons.javaflow.bytecode.transformation.bcel.BcelClassTransformer;
-import org.apache.commons.io.IOUtils;
+import org.apache.commons.javaflow.utils.RewritingUtils;
 
 import java.io.IOException;
 
@@ -34,7 +34,7 @@
         if(args.length>0 && args[0].equals("asm"))
             trans = new AsmClassTransformer();
 
-        byte[] out = trans.transform(IOUtils.toByteArray(System.in));
+        byte[] out = trans.transform(RewritingUtils.toByteArray(System.in));
         System.out.write(out);
     }
 }

Modified: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/TestClassLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/TestClassLoader.java?rev=360306&r1=360305&r2=360306&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/TestClassLoader.java
(original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/TestClassLoader.java
Sat Dec 31 07:52:45 2005
@@ -2,7 +2,7 @@
 
 import org.apache.commons.javaflow.bytecode.transformation.ResourceTransformer;
 import org.apache.commons.javaflow.bytecode.transformation.bcel.BcelClassTransformer;
-import org.apache.commons.io.IOUtils;
+import org.apache.commons.javaflow.utils.RewritingUtils;
 
 import java.io.InputStream;
 import java.io.IOException;
@@ -46,7 +46,7 @@
             InputStream is = super.getResourceAsStream(name.replace('.', '/') + ".class");
             if(is!=null) {
                 try {
-                    byte[] buf = IOUtils.toByteArray(is);
+                    byte[] buf = RewritingUtils.toByteArray(is);
                     buf = transformer.transform(buf);
                     c = defineClass(name, buf, 0, buf.length);
                 } catch (IOException e) {

Modified: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/flow/NullVariableMethodFlow.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/flow/NullVariableMethodFlow.java?rev=360306&r1=360305&r2=360306&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/flow/NullVariableMethodFlow.java
(original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/flow/NullVariableMethodFlow.java
Sat Dec 31 07:52:45 2005
@@ -1,6 +1,8 @@
 package org.apache.commons.javaflow.flow;
 
 import java.util.Properties;
+import java.util.NoSuchElementException;
+import java.util.Vector;
 
 /**
  * A regression test case for handling null in the local variables.



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message