am d3c9ec81
: Merge "Close file properly"
# Via Android (Google) Code Review (1) and Kurt Partridge (1) * commit 'd3c9ec8133ae203b10eafc8547cbda51d995a44e': Close file properly
This commit is contained in:
commit
71bc485b09
1 changed files with 12 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue