LevelDB implements AutoCloseable { public void compactRange(byte[] startKey, byte[] limitKey) { checkDatabaseOpen(); if (Native.POINTER_SIZE == 8) { long startKeyLength = startKey != null ? startKey.length : 0; long limitKeyLength = limitKey != null ? limitKey.length : 0; LevelDBNative.leveldb_compact_range(levelDB, startKey, startKeyLength, limitKey, limitKeyLength); } else { int startKeyLength = startKey != null ? startKey.length : 0; int limitKeyLength = limitKey != null ? limitKey.length : 0; LevelDBNative.leveldb_compact_range(levelDB, startKey, startKeyLength, limitKey, limitKeyLength); } } 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 compact_all_range() { try(LevelDBOptions options = new LevelDBOptions()) { options.setCreateIfMissing(true); try (LevelDB levelDB = new LevelDB(testFolder.getRoot().getAbsolutePath(), options)) { levelDB.compactRange(null, null); } } }
@Test public void compact_range() { try(LevelDBOptions options = new LevelDBOptions()) { options.setCreateIfMissing(true); try (LevelDB levelDB = new LevelDB(testFolder.getRoot().getAbsolutePath(), options)) { levelDB.compactRange(new byte[] {'a'}, new byte[] {'z'}); } } }