From 2cabb7aed0440dd40aec15d4d46451ddef278c6c Mon Sep 17 00:00:00 2001 From: Kurt Partridge Date: Thu, 7 Feb 2013 09:57:53 -0800 Subject: [PATCH] Close file properly Change-Id: Ied55b6a6f1e64bbca558316d8d3d207d7655cf91 --- .../inputmethod/research/ResearchLogger.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java index 364ab2da2..90541e868 100644 --- a/java/src/com/android/inputmethod/research/ResearchLogger.java +++ b/java/src/com/android/inputmethod/research/ResearchLogger.java @@ -763,18 +763,26 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang if (isIncludingRecording) { // Try to read recording from recently written json file if (mUserRecordingFile != null) { + FileChannel channel = null; try { - final FileChannel channel = - new FileInputStream(mUserRecordingFile).getChannel(); + channel = new FileInputStream(mUserRecordingFile).getChannel(); final MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); // Android's openFileOutput() creates the file, so we use Android's default // Charset (UTF-8) here to read it. recording = Charset.defaultCharset().decode(buffer).toString(); } catch (FileNotFoundException e) { - e.printStackTrace(); + Log.e(TAG, "Could not find recording file", e); } catch (IOException e) { - e.printStackTrace(); + Log.e(TAG, "Error reading recording file", e); + } finally { + if (channel != null) { + try { + channel.close(); + } catch (IOException e) { + Log.e(TAG, "Error closing recording file", e); + } + } } } }