LevelDB implements AutoCloseable { public byte[] get(byte[] key, LevelDBReadOptions readOptions) { checkDatabaseOpen(); readOptions.checkReadOptionsOpen(); PointerByReference resultLengthPointer = new PointerByReference(); PointerByReference result; long resultLength; PointerByReference error = new PointerByReference(); if (Native.POINTER_SIZE == 8) { long keyLength = key != null ? key.length : 0; result = LevelDBNative.leveldb_get(levelDB, readOptions.readOptions, key, keyLength, resultLengthPointer, error); LevelDBNative.checkError(error); resultLength = resultLengthPointer.getPointer().getLong(0); } else { int keyLength = key != null ? key.length : 0; result = LevelDBNative.leveldb_get(levelDB, readOptions.readOptions, key, keyLength, resultLengthPointer, error); LevelDBNative.checkError(error); resultLength = resultLengthPointer.getPointer().getInt(0); } byte[] resultAsByteArray = null; if (result != null) { resultAsByteArray = result.getPointer().getByteArray(0, (int) resultLength); LevelDBNative.leveldb_free(result.getPointer()); } return resultAsByteArray; } 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 get_null_key() { try(LevelDBOptions options = new LevelDBOptions()) { options.setCreateIfMissing(true); try(LevelDBReadOptions readOptions = new LevelDBReadOptions()) { try (LevelDB levelDB = new LevelDB(testFolder.getRoot().getAbsolutePath(), options)) { byte[] result = levelDB.get(null, readOptions); Assert.assertEquals(null, result); } } } }
@Test public void get_not_exists_key() { try(LevelDBOptions options = new LevelDBOptions()) { options.setCreateIfMissing(true); try(LevelDBReadOptions readOptions = new LevelDBReadOptions()) { try (LevelDB levelDB = new LevelDB(testFolder.getRoot().getAbsolutePath(), options)) { byte[] result = levelDB.get(new byte[]{}, readOptions); Assert.assertEquals(null, result); } } } }