[jboss-cvs] JBossAS SVN: r80613 - projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/plugins.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 6 15:46:18 EST 2008


Author: alesj
Date: 2008-11-06 15:46:18 -0500 (Thu, 06 Nov 2008)
New Revision: 80613

Modified:
   projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/plugins/ClassLoaderUtils.java
Log:
Remove duplicated code.

Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/plugins/ClassLoaderUtils.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/plugins/ClassLoaderUtils.java	2008-11-06 19:35:50 UTC (rev 80612)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/plugins/ClassLoaderUtils.java	2008-11-06 20:46:18 UTC (rev 80613)
@@ -33,6 +33,7 @@
  * ClassLoaderUtils.
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision: 1.1 $
  */
 public class ClassLoaderUtils
@@ -144,12 +145,7 @@
    {
       try
       {
-         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-         byte[] tmp = new byte[1024];
-         int read = 0;
-         while ( (read = is.read(tmp)) >= 0 )
-            baos.write(tmp, 0, read);
-         return baos.toByteArray();
+         return readBytes(is);
       }
       catch (IOException e)
       {
@@ -179,12 +175,7 @@
    {
       try
       {
-         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-         byte[] tmp = new byte[1024];
-         int read = 0;
-         while ( (read = is.read(tmp)) >= 0 )
-            baos.write(tmp, 0, read);
-         return baos.toByteArray();
+         return readBytes(is);
       }
       finally
       {
@@ -198,8 +189,32 @@
          }
       }
    }
-   
+
    /**
+    * Read bytes.
+    * Doesn't close inputstream.
+    *
+    * @param is the input stream
+    * @return the bytes
+    * @throws IOException for any error
+    * @throws IllegalArgumentException for null is parameter
+    */
+   protected static final byte[] readBytes(final InputStream is) throws IOException
+   {
+      if (is == null)
+         throw new IllegalArgumentException("Null input stream.");
+
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      byte[] tmp = new byte[1024];
+      int read ;
+      while ((read = is.read(tmp)) >= 0)
+      {
+         baos.write(tmp, 0, read);
+      }
+      return baos.toByteArray();
+   }
+
+   /**
     * Formats the class as a string
     * 
     * @param clazz the class




More information about the jboss-cvs-commits mailing list