Skip to content

Commit 1969758

Browse files
committed
Refining the use of RandomAccessFile with the help of local variables.
1 parent 9801199 commit 1969758

File tree

1 file changed

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

1 file changed

+7
-9
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ private void expandIfNecessary(int dataLength, RandomAccessFile raf) throws IOEx
419419
previousLength = newLength;
420420
} while (remainingBytes < elementLength);
421421

422-
setLength(newLength);
422+
setLength(newLength, raf);
423423

424424
// Calculate the position of the tail end of the data in the ring buffer
425425
int endOfLastElement = wrapPosition(last.position + Element.HEADER_LENGTH + last.length);
@@ -449,12 +449,10 @@ private void expandIfNecessary(int dataLength, RandomAccessFile raf) throws IOEx
449449
/**
450450
* Sets the length of the file.
451451
*/
452-
private void setLength(int newLength) throws IOException {
453-
openAndExecute(raf -> {
454-
// Set new file length (considered metadata) and sync it to storage.
455-
raf.setLength(newLength);
456-
raf.getChannel().force(true);
457-
});
452+
private void setLength(int newLength, RandomAccessFile raf) throws IOException {
453+
// Set new file length (considered metadata) and sync it to storage.
454+
raf.setLength(newLength);
455+
raf.getChannel().force(true);
458456
}
459457

460458
/**
@@ -588,13 +586,13 @@ public synchronized void remove() throws IOException {
588586
/**
589587
* Clears this queue. Truncates the file to the initial size.
590588
*/
591-
public synchronized void clear(RandomAccessFile raf) throws IOException {
589+
private synchronized void clear(RandomAccessFile raf) throws IOException {
592590
writeHeader(INITIAL_LENGTH, 0, 0, 0, raf);
593591
elementCount = 0;
594592
first = Element.NULL;
595593
last = Element.NULL;
596594
if (fileLength > INITIAL_LENGTH) {
597-
setLength(INITIAL_LENGTH);
595+
setLength(INITIAL_LENGTH, raf);
598596
}
599597
fileLength = INITIAL_LENGTH;
600598
}

0 commit comments

Comments
 (0)