Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 77808 invoked from network); 6 Feb 2008 21:24:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Feb 2008 21:24:27 -0000 Received: (qmail 39426 invoked by uid 500); 6 Feb 2008 21:24:18 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 39363 invoked by uid 500); 6 Feb 2008 21:24:18 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 39354 invoked by uid 99); 6 Feb 2008 21:24:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Feb 2008 13:24:18 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Feb 2008 21:23:57 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id F24751A9832; Wed, 6 Feb 2008 13:24:03 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r619156 - in /commons/proper/io/trunk/src/java/org/apache/commons/io: FileUtils.java IOUtils.java Date: Wed, 06 Feb 2008 21:24:03 -0000 To: commits@commons.apache.org From: niallp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080206212403.F24751A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 Channel. + *

+ * 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