← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1823: Small refactor to allow copying of streams.

 

------------------------------------------------------------
revno: 1823
committer: Bob Jolliffe <bobj@bobj-laptop>
branch nick: trunk
timestamp: Thu 2010-05-06 12:38:23 +0100
message:
  Small refactor to allow copying of streams.
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/StreamUtils.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/StreamUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/StreamUtils.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/StreamUtils.java	2010-05-06 11:38:23 +0000
@@ -75,6 +75,27 @@
         return classLoader.getResourceAsStream( name );
     }
 
+    public static void streamcopy(BufferedInputStream in, BufferedOutputStream out)
+    {
+        int b = 0;
+
+        try
+        {
+           while ( ( b = in.read() ) != -1 )
+            {
+                out.write( b );
+            }
+        }
+        catch ( IOException ex )
+        {
+            throw new RuntimeException( ex );
+        }
+        finally
+        {
+            closeInputStream( in );
+            closeOutputStream( out );
+        }
+    }
     /**
      * Writes the content of the first File to the second File.
      * 
@@ -85,18 +106,12 @@
     {
         BufferedInputStream in = null;
         BufferedOutputStream out = null;
-        
-        int b = 0;
-        
-        try
-        {
+
+        try {
             in = new BufferedInputStream( new FileInputStream( inFile ) );
             out = new BufferedOutputStream( new FileOutputStream( outFile ) );
-            
-            while ( ( b = in.read() ) != -1 )
-            {
-                out.write( b );
-            }
+
+            streamcopy(in, out);
         }
         catch ( IOException ex )
         {
@@ -106,8 +121,8 @@
         {
             closeInputStream( in );
             closeOutputStream( out );
-
         }
+        
     }
 
     /**