Skip to content

Commit a820d31

Browse files
committed
Aim for the right RAF method in order to handle FileChannel instance.
1 parent 5056a8f commit a820d31

File tree

1 file changed

+8
-9
lines changed
  • firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/metadata

1 file changed

+8
-9
lines changed

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/metadata/QueueFile.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -428,15 +428,14 @@ private void expandIfNecessary(int dataLength) throws IOException {
428428

429429
// If the buffer is split, we need to make it contiguous
430430
if (endOfLastElement < first.position) {
431-
FileChannel channel;
432-
try (RandomAccessFile raf = open(rafFile)) {
433-
channel = raf.getChannel();
434-
}
435-
channel.position(fileLength); // destination position
436-
int count = endOfLastElement - Element.HEADER_LENGTH;
437-
if (channel.transferTo(HEADER_LENGTH, count, channel) != count) {
438-
throw new AssertionError("Copied insufficient number of bytes!");
439-
}
431+
openAndExecute(raf -> {
432+
FileChannel channel = raf.getChannel();
433+
channel.position(fileLength); // destination position
434+
int count = endOfLastElement - Element.HEADER_LENGTH;
435+
if (channel.transferTo(HEADER_LENGTH, count, channel) != count) {
436+
throw new AssertionError("Copied insufficient number of bytes!");
437+
}
438+
});
440439
}
441440

442441
// Commit the expansion.

0 commit comments

Comments
 (0)