Skip to content

Commit 04c2e75

Browse files
committed
BoxStore: add sizeOnDisk()
1 parent 9e1f6f5 commit 04c2e75

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

objectbox-java/src/main/java/io/objectbox/BoxStore.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,16 @@ static boolean isFileOpenSync(String canonicalPath, boolean runFinalization) {
332332
}
333333
}
334334

335+
/**
336+
* The size in bytes occupied by the data file on disk.
337+
*
338+
* @return 0 if the size could not be determined (does not throw unless this store was already closed)
339+
*/
340+
public long sizeOnDisk() {
341+
checkOpen();
342+
return nativeSizeOnDisk(handle);
343+
}
344+
335345
/**
336346
* Explicitly call {@link #close()} instead to avoid expensive finalization.
337347
*/

tests/objectbox-java-test/src/test/java/io/objectbox/BoxStoreTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,10 @@ private Callable<String> createTestCallable(final int[] countHolder) {
215215
};
216216
}
217217

218+
@Test
219+
public void testSizeOnDisk() {
220+
long size = store.sizeOnDisk();
221+
assertTrue(size >= 8192);
222+
}
223+
218224
}

0 commit comments

Comments
 (0)