You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ivy-commits@incubator.apache.org by ma...@apache.org on 2007/01/07 22:38:07 UTC

svn commit: r493869 - /incubator/ivy/trunk/src/java/org/apache/ivy/util/FileUtil.java

Author: maartenc
Date: Sun Jan  7 14:38:06 2007
New Revision: 493869

URL: http://svn.apache.org/viewvc?view=rev&rev=493869
Log:
Call end() after closing the streams.

Modified:
    incubator/ivy/trunk/src/java/org/apache/ivy/util/FileUtil.java

Modified: incubator/ivy/trunk/src/java/org/apache/ivy/util/FileUtil.java
URL: http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/util/FileUtil.java?view=diff&rev=493869&r1=493868&r2=493869
==============================================================================
--- incubator/ivy/trunk/src/java/org/apache/ivy/util/FileUtil.java (original)
+++ incubator/ivy/trunk/src/java/org/apache/ivy/util/FileUtil.java Sun Jan  7 14:38:06 2007
@@ -42,9 +42,10 @@
  *
  */
 public class FileUtil {
-    // tried some other values with empty files... seems to be the best one (512 * 1024 is very bad)
+	// tried some other values with empty files... seems to be the best one (512 * 1024 is very bad)
     // 8 * 1024 is also the size used by ant in its FileUtils... maybe they've done more study about it ;-)
     private static final int BUFFER_SIZE = 8 * 1024;
+    private static final byte[] EMPTY_BUFFER = new byte[0];
 
     public static void symlink(File src, File dest, CopyProgressListener l, boolean overwrite) throws IOException {
         try {
@@ -131,11 +132,11 @@
     }
 
     public static void copy(InputStream src, OutputStream dest, CopyProgressListener l) throws IOException {
+        CopyProgressEvent evt = null;
+        if (l != null) {
+            evt = new CopyProgressEvent();
+        }
         try {
-            CopyProgressEvent evt = null;
-            if (l != null) {
-                evt = new CopyProgressEvent();
-            }
             byte buffer[]=new byte[BUFFER_SIZE];
             int c;
             long total = 0;
@@ -153,17 +154,26 @@
                     l.progress(evt.update(buffer, c, total));
                 }
             } 
-            if (l != null) {
-                l.end(evt.update(buffer, 0, total));
-            }
+            evt.update(EMPTY_BUFFER, 0, total);
+            
+            // close the streams
+            src.close();
+            dest.close();
         } finally {
             try {
                 src.close();
             } catch (IOException ex) {
-                dest.close();
-                throw ex;
+            	// ignore
             }
-            dest.close();
+            try {
+            	dest.close();
+            } catch (IOException ex) {
+            	// ignore
+            }
+        }
+        
+        if (l != null) {
+            l.end(evt);
         }
     }