1 /*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <jni.h>
18 #include <nativehelper/JNIHelp.h>
19
Java_libcore_java_nio_BufferTest_jniGetDirectBufferAddress(JNIEnv * env,jobject,jobject buffer)20 extern "C" jlong Java_libcore_java_nio_BufferTest_jniGetDirectBufferAddress(
21 JNIEnv* env, jobject /* clazz */, jobject buffer) {
22 return reinterpret_cast<jlong>(env->GetDirectBufferAddress(buffer));
23 }
24
Java_libcore_java_nio_BufferTest_jniGetDirectBufferCapacity(JNIEnv * env,jobject,jobject buffer)25 extern "C" jlong Java_libcore_java_nio_BufferTest_jniGetDirectBufferCapacity(
26 JNIEnv* env, jobject /* clazz */, jobject buffer) {
27 return reinterpret_cast<jlong>(env->GetDirectBufferCapacity(buffer));
28 }
29
Java_libcore_java_nio_BufferTest_jniNewDirectByteBuffer(JNIEnv * env,jobject)30 extern "C" jobject Java_libcore_java_nio_BufferTest_jniNewDirectByteBuffer(
31 JNIEnv* env, jobject /* clazz */) {
32 // We use (nullptr, 0) here because a DirectByteBuffer is allowed to wrap
33 // nullptr providing the buffer is zero length.
34 return env->NewDirectByteBuffer(nullptr, 0);
35 }
36