Skip to content
Snippets Groups Projects
Commit 2cabb7ae authored by Kurt Partridge's avatar Kurt Partridge
Browse files

Close file properly

Change-Id: Ied55b6a6f1e64bbca558316d8d3d207d7655cf91
parent 3623ad23
No related branches found
No related tags found
No related merge requests found
...@@ -763,18 +763,26 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang ...@@ -763,18 +763,26 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
if (isIncludingRecording) { if (isIncludingRecording) {
// Try to read recording from recently written json file // Try to read recording from recently written json file
if (mUserRecordingFile != null) { if (mUserRecordingFile != null) {
FileChannel channel = null;
try { try {
final FileChannel channel = channel = new FileInputStream(mUserRecordingFile).getChannel();
new FileInputStream(mUserRecordingFile).getChannel();
final MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, final MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0,
channel.size()); channel.size());
// Android's openFileOutput() creates the file, so we use Android's default // Android's openFileOutput() creates the file, so we use Android's default
// Charset (UTF-8) here to read it. // Charset (UTF-8) here to read it.
recording = Charset.defaultCharset().decode(buffer).toString(); recording = Charset.defaultCharset().decode(buffer).toString();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); Log.e(TAG, "Could not find recording file", e);
} catch (IOException 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);
}
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment