From 3e2670265e17e91c5a8cfff01711f973dccd2a0c Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Wed, 24 Feb 2016 20:08:27 -0800 Subject: [PATCH] Close FileChannels in UpdateHandler#copyFile. Bug: 26239281 Change-Id: Ib30beb3548f8fb4a8e338b5da863ae28c252bc2b --- .../inputmethod/dictionarypack/UpdateHandler.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java index 0517bc814..6b32c684f 100644 --- a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java +++ b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java @@ -689,8 +689,16 @@ public final class UpdateHandler { } else { try { final FileChannel sourceChannel = ((FileInputStream) in).getChannel(); - final FileChannel destinationChannel = ((FileOutputStream) out).getChannel(); - sourceChannel.transferTo(0, Integer.MAX_VALUE, destinationChannel); + try { + final FileChannel destinationChannel = ((FileOutputStream) out).getChannel(); + try { + sourceChannel.transferTo(0, Integer.MAX_VALUE, destinationChannel); + } finally { + destinationChannel.close(); + } + } finally { + sourceChannel.close(); + } } catch (IOException e) { // Can't work with channels, or something went wrong. Copy by hand. DebugLogUtils.l("Won't work");