You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ni...@apache.org on 2008/02/06 22:24:03 UTC
svn commit: r619156 - in
/commons/proper/io/trunk/src/java/org/apache/commons/io: FileUtils.java
IOUtils.java
Author: niallp
Date: Wed Feb 6 13:24:02 2008
New Revision: 619156
URL: http://svn.apache.org/viewvc?rev=619156&view=rev
Log:
IO-155 Use nio to copy files - based on a patch from Nicolas de Loof
Modified:
commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java
Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java?rev=619156&r1=619155&r2=619156&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java Wed Feb 6 13:24:02 2008
@@ -25,6 +25,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
+import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@@ -666,11 +667,11 @@
throw new IOException("Destination '" + destFile + "' exists but is a directory");
}
- FileInputStream input = new FileInputStream(srcFile);
+ FileChannel input = new FileInputStream(srcFile).getChannel();
try {
- FileOutputStream output = new FileOutputStream(destFile);
+ FileChannel output = new FileOutputStream(destFile).getChannel();
try {
- IOUtils.copy(input, output);
+ output.transferFrom(input, 0, input.size());
} finally {
IOUtils.closeQuietly(output);
}
Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java?rev=619156&r1=619155&r2=619156&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java Wed Feb 6 13:24:02 2008
@@ -30,6 +30,7 @@
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
+import java.nio.channels.Channel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -140,6 +141,24 @@
try {
if (input != null) {
input.close();
+ }
+ } catch (IOException ioe) {
+ // ignore
+ }
+ }
+
+ /**
+ * Unconditionally close a <code>Channel</code>.
+ * <p>
+ * Equivalent to {@link Channel#close()}, except any exceptions will be ignored.
+ * This is typically used in finally blocks.
+ *
+ * @param channel the Channel to close, may be null or already closed
+ */
+ public static void closeQuietly(Channel channel) {
+ try {
+ if (channel != null) {
+ channel.close();
}
} catch (IOException ioe) {
// ignore