Giter Club home page Giter Club logo

jleveldb's Introduction

jleveldb

A bare bones JNI wrapper for the LevelDB project (http://code.google.com/p/leveldb/)

This project wraps the C-interface to LevelDB with JNI code, exposing it to Java. It is
missing about 3 functions that have callbacks or other weirdness I haven't gotten to yet.

It comes with pre-built LevelDB libraries for OSX 10.6+ and Linux 2.6 (both 64-bit). It
comes with a makefile that should product a JNI library and a jarfile for those platforms.
It also comes with inadequate, but easily expanded, test-coverage.

Note that the libleveldb-linux.a library was built with the -fPIC flag.

It shouldn't be too much work to update the makefile to build for other platforms or
architectures.

The following make targets are useful:
make clean
make
make test

It uses Java longs to represent pointers in native code. This is a hack that seems to work
reasonably well. Be aware that if you pass the wrong kind of structure for a given
parameter, your process will likely crash.

I plan to build a java layer on top of this that more closely mirrors the native LevelDB
API when I get a chance.

This code likely has some bugs yet, as the test coverage is thin. Reproducers and pull
requests welcome.

Here is some sample code:

===========

NativeInterface ni = new NativeInterface();

long options = ni.leveldb_options_create();
ni.leveldb_options_set_create_if_missing(options, true);
long writeoptions = ni.leveldb_writeoptions_create();
long readoptions = ni.leveldb_readoptions_create();

long db = ni.leveldb_open(options, "testfile.leveldb");
ni.leveldb_put(db, writeoptions, "key".getBytes(), "value".getBytes());
byte[] value = ni.leveldb_get(db, readoptions, "key".getBytes());
assertTrue(Arrays.equals("value".getBytes(), value));
ni.leveldb_close(db);
ni.leveldb_destroy_db(options, "testfile.leveldb");

ni.leveldb_options_destroy(options);
ni.leveldb_readoptions_destroy(readoptions);
ni.leveldb_writeoptions_destroy(writeoptions);

===========

jleveldb's People

Contributors

jhugg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.