Fix warning about .close() not being called in FileUtils.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/0a669077 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/0a669077 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/0a669077 Branch: refs/heads/master Commit: 0a669077fb95b3d365b0618515fc742728ea8cad Parents: 451688a Author: Andrew Grieve <agri...@chromium.org> Authored: Fri Sep 7 11:11:19 2012 -0400 Committer: Andrew Grieve <agri...@chromium.org> Committed: Tue Sep 18 13:23:26 2012 -0400 ---------------------------------------------------------------------- framework/src/org/apache/cordova/FileUtils.java | 39 +++++++++-------- 1 files changed, 21 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/0a669077/framework/src/org/apache/cordova/FileUtils.java ---------------------------------------------------------------------- diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java index a27632f..1c8f084 100755 --- a/framework/src/org/apache/cordova/FileUtils.java +++ b/framework/src/org/apache/cordova/FileUtils.java @@ -409,19 +409,19 @@ public class FileUtils extends Plugin { throw new InvalidModificationException("Can't rename a file to a directory"); } - FileChannel input = new FileInputStream(srcFile).getChannel(); - FileChannel output = new FileOutputStream(destFile).getChannel(); + FileInputStream istream = new FileInputStream(srcFile); + FileOutputStream ostream = new FileOutputStream(destFile); + FileChannel input = istream.getChannel(); + FileChannel output = ostream.getChannel(); - input.transferTo(0, input.size(), output); - - input.close(); - output.close(); - - /* - if (srcFile.length() != destFile.length()) { - return false; + try { + input.transferTo(0, input.size(), output); + } finally { + istream.close(); + ostream.close(); + input.close(); + output.close(); } - */ return getEntry(destFile); } @@ -1008,14 +1008,17 @@ public class FileUtils extends Plugin { filename = stripFileProtocol(filename); RandomAccessFile raf = new RandomAccessFile(filename, "rw"); - - if (raf.length() >= size) { - FileChannel channel = raf.getChannel(); - channel.truncate(size); - return size; + try { + if (raf.length() >= size) { + FileChannel channel = raf.getChannel(); + channel.truncate(size); + return size; + } + + return raf.length(); + } finally { + raf.close(); } - - return raf.length(); } /**