// Copyright (c) 2014, Facebook, Inc. All rights reserved. // This source code is licensed under the BSD-style license found in the // LICENSE file in the root directory of this source tree. An additional grant // of patent rights can be found in the PATENTS file in the same directory. // // This file implements the "bridge" between Java and C++ for // rocksdb::Slice. #include #include #include #include #include "include/org_rocksdb_AbstractSlice.h" #include "include/org_rocksdb_Slice.h" #include "include/org_rocksdb_DirectSlice.h" #include "rocksdb/slice.h" #include "rocksjni/portal.h" // /* * Class: org_rocksdb_Slice * Method: createNewSlice0 * Signature: ([BI)V */ void Java_org_rocksdb_Slice_createNewSlice0( JNIEnv * env, jobject jobj, jbyteArray data, jint offset) { const jsize dataSize = env->GetArrayLength(data); const int len = dataSize - offset; //jbyte ptrData[len]; jbyte* ptrData = new jbyte[len]; env->GetByteArrayRegion(data, offset, len, ptrData); const rocksdb::Slice* slice = new rocksdb::Slice((const char*)ptrData, len); rocksdb::AbstractSliceJni::setHandle(env, jobj, slice); } /* * Class: org_rocksdb_Slice * Method: createNewSlice1 * Signature: ([B)V */ void Java_org_rocksdb_Slice_createNewSlice1( JNIEnv * env, jobject jobj, jbyteArray data) { jboolean isCopy; jbyte* ptrData = env->GetByteArrayElements(data, &isCopy); const rocksdb::Slice* slice = new rocksdb::Slice((const char*)ptrData, env->GetArrayLength(data)); rocksdb::AbstractSliceJni::setHandle(env, jobj, slice); env->ReleaseByteArrayElements(data, ptrData, JNI_COMMIT); //TODO where do we free ptrData later? //do we need to call env->ReleaseByteArrayElements(data, ptrData, JNI_ABORT) in the org.rocksdb.Slice#dispose() method? } /* * Class: org_rocksdb_Slice * Method: data0 * Signature: (J)[B */ jbyteArray Java_org_rocksdb_Slice_data0( JNIEnv* env, jobject jobj, jlong handle) { const rocksdb::Slice* slice = reinterpret_cast(handle); const int len = slice->size(); const jbyteArray data = env->NewByteArray(len); env->SetByteArrayRegion(data, 0, len, (jbyte*)slice->data()); return data; } // //