copy the c version and add the jni methods (not implemented)

Signed-off-by: Mattias Andrée <maandree@operamail.com>