LevelDB implements AutoCloseable { public long[] approximateSizes(Range ...ranges) { checkDatabaseOpen(); if (ranges.length == 0) return new long[0]; Memory startKeys = new Memory(ranges.length * Pointer.SIZE); Memory limitKeys = new Memory(ranges.length * Pointer.SIZE); for (int i = 0; i < ranges.length; i++) { int startKeyLength = ranges[i].getStartKey().length; Memory startKeyMemory = new Memory(startKeyLength); startKeyMemory.write(0, ranges[i].getStartKey(), 0, startKeyLength); startKeys.setPointer(i * Pointer.SIZE, startKeyMemory); int limitKeyLength = ranges[i].getLimitKey().length; Memory limitKeyMemory = new Memory(limitKeyLength); limitKeyMemory.write(0, ranges[i].getLimitKey(), 0, limitKeyLength); limitKeys.setPointer(i * Pointer.SIZE, limitKeyMemory); } Pointer sizes = new Memory(ranges.length * Native.getNativeSize(Long.TYPE)); if (Native.POINTER_SIZE == 8) { long[] startLengths = new long[ranges.length]; long[] limitLengths = new long[ranges.length]; for (int i = 0; i < ranges.length; i++) { startLengths[i] = ranges[i].getStartKey().length; limitLengths[i] = ranges[i].getLimitKey().length; } LevelDBNative.leveldb_approximate_sizes(levelDB, ranges.length, startKeys, startLengths, limitKeys, limitLengths, sizes); } else { int[] startLengths = new int[ranges.length]; int[] limitLengths = new int[ranges.length]; for (int i = 0; i < ranges.length; i++) { startLengths[i] = ranges[i].getStartKey().length; limitLengths[i] = ranges[i].getLimitKey().length; } LevelDBNative.leveldb_approximate_sizes(levelDB, ranges.length, startKeys, startLengths, limitKeys, limitLengths, sizes); } return sizes.getLongArray(0, ranges.length); } LevelDB(String levelDBDirectory, LevelDBOptions options); void close(); byte[] get(byte[] key, LevelDBReadOptions readOptions); void put(byte[] key, byte[] value, LevelDBWriteOptions writeOptions); void write(LevelDBWriteBatch writeBatch, LevelDBWriteOptions writeOptions); void delete(byte[] key, LevelDBWriteOptions writeOptions); String property(String property); long[] approximateSizes(Range ...ranges); void compactRange(byte[] startKey, byte[] limitKey); static void repair(String levelDBDirectory, LevelDBOptions options); static void destroy(String levelDBDirectory, LevelDBOptions options); static int majorVersion(); static int minorVersion();  }
@Test public void approximate_sizes_for_empty_ranges() { try(LevelDBOptions options = new LevelDBOptions()) { options.setCreateIfMissing(true); try (LevelDB levelDB = new LevelDB(testFolder.getRoot().getAbsolutePath(), options)) { long[] sizes = levelDB.approximateSizes(); Assert.assertArrayEquals(new long[0], sizes); } } }