@@ -66,31 +66,38 @@ public static void writeTokenToInternalStorage(Context context, String token) {
66
66
// Write out the buffer length into the first four bytes.
67
67
sizeBuffer .order (ByteOrder .LITTLE_ENDIAN );
68
68
sizeBuffer .putInt (buffer .length );
69
- FileLock lock = null ;
70
- try {
71
- // Acquire lock. This prevents the C++ code from consuming and clearing the file while we
72
- // append to it.
73
- FileOutputStream lockFileStream = context .openFileOutput (MessageWriter .LOCK_FILE , 0 );
74
- lock = lockFileStream .getChannel ().lock ();
75
69
76
- FileOutputStream outputStream =
77
- context .openFileOutput (MessageWriter .STORAGE_FILE , Context .MODE_APPEND );
78
- // We send both the buffer length and the buffer itself so that we can potentially process
79
- // more than one event in the case where they get queued up.
70
+ // try (FileOutputStream lockFileStream = context.openFileOutput(MessageWriter.LOCK_FILE, 0)) {
71
+ // // Acquire lock. This prevents the C++ code from consuming and clearing the file while we
72
+ // // append to it.
73
+ // try (FileLock lock = lockFileStream.getChannel().lock()) {
74
+ // try (FileOutputStream outputStream =
75
+ // context.openFileOutput(MessageWriter.STORAGE_FILE, Context.MODE_APPEND)) {
76
+ // // We send both the buffer length and the buffer itself so that we can potentially
77
+ // // process more than one event in the case where they get queued up.
78
+ // outputStream.write(sizeBuffer.array());
79
+ // outputStream.write(buffer);
80
+ // } catch (Exception e) {
81
+ // e.printStackTrace();
82
+ // }
83
+ // } catch (Exception e) {
84
+ // e.printStackTrace();
85
+ // }
86
+ // } catch (Exception e) {
87
+ // e.printStackTrace();
88
+ // }
89
+ try (FileOutputStream lockFileStream = context .openFileOutput (MessageWriter .LOCK_FILE , 0 );
90
+ // Acquire lock. This prevents the C++ code from consuming and clearing the file while we
91
+ // append to it.
92
+ FileLock lock = lockFileStream .getChannel ().lock ();
93
+ FileOutputStream outputStream =
94
+ context .openFileOutput (MessageWriter .STORAGE_FILE , Context .MODE_APPEND )) {
95
+ // We send both the buffer length and the buffer itself so that we can potentially
96
+ // process more than one event in the case where they get queued up.
80
97
outputStream .write (sizeBuffer .array ());
81
98
outputStream .write (buffer );
82
- outputStream .close ();
83
99
} catch (Exception e ) {
84
- e .printStackTrace ();
85
- } finally {
86
- // Release the lock.
87
- try {
88
- if (lock != null ) {
89
- lock .release ();
90
- }
91
- } catch (Exception e ) {
92
100
e .printStackTrace ();
93
- }
94
101
}
95
102
}
96
103
0 commit comments