Author: bodewig
Date: Sat Jan 11 18:11:01 2014
New Revision: 1557433

URL: http://svn.apache.org/r1557433
Log:
Fall back to stream based copy if channel based copy fails for some reason - 
PRs 53102 and 54397

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java?rev=1557433&r1=1557432&r2=1557433&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java 
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java Sat 
Jan 11 18:11:01 2014
@@ -426,13 +426,26 @@ public class ResourceUtils {
                                               filterChainsAvailable, append,
                                               effectiveInputEncoding,
                                               outputEncoding, project);
-        } else if (source.as(FileProvider.class) != null
-                   && destFile != null && !append) {
-            File sourceFile =
-                source.as(FileProvider.class).getFile();
-            copyUsingFileChannels(sourceFile, destFile);
         } else {
-            copyUsingStreams(source, dest, append, project);
+            boolean copied = false;
+            if (source.as(FileProvider.class) != null
+                && destFile != null && !append) {
+                File sourceFile =
+                    source.as(FileProvider.class).getFile();
+                try {
+                    copyUsingFileChannels(sourceFile, destFile);
+                    copied = true;
+                } catch (IOException ex) {
+                    project.log("Attempt to copy " + sourceFile
+                                + " to " + destFile + " using NIO Channels"
+                                + " failed due to '" + ex.getMessage()
+                                + "'.  Falling back to streams.",
+                                Project.MSG_WARN);
+                }
+            }
+            if (!copied) {
+                copyUsingStreams(source, dest, append, project);
+            }
         }
         if (preserveLastModified) {
             Touchable t = dest.as(Touchable.class);


Reply via email to