Skip to content

Commit

Permalink
Fix #973 Make sure all resources are closed
Browse files Browse the repository at this point in the history
Make sure all FileStream and FileLock are closed using AutoClose pattern.
  • Loading branch information
chkuang-g committed Jun 17, 2022
1 parent d8abadc commit 05f20ca
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ public static void writeTokenToInternalStorage(Context context, String token) {
// e.printStackTrace();
// }
try (FileOutputStream lockFileStream = context.openFileOutput(MessageWriter.LOCK_FILE, 0);
// Acquire lock. This prevents the C++ code from consuming and clearing the file while we
// append to it.
FileLock lock = lockFileStream.getChannel().lock();
FileOutputStream outputStream =
context.openFileOutput(MessageWriter.STORAGE_FILE, Context.MODE_APPEND)) {
// Acquire lock. This prevents the C++ code from consuming and clearing the file while we
// append to it.
FileLock lock = lockFileStream.getChannel().lock();
FileOutputStream outputStream =
context.openFileOutput(MessageWriter.STORAGE_FILE, Context.MODE_APPEND)) {
// We send both the buffer length and the buffer itself so that we can potentially
// process more than one event in the case where they get queued up.
outputStream.write(sizeBuffer.array());
outputStream.write(buffer);
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
}
}

Expand Down

0 comments on commit 05f20ca

Please sign in to comment.