#include #include "org_apache_mina_jni_ByteBufferAllocator.h" /* * Class: org_apache_mina_jni_ByteBufferAllocator * Method: _allocate * Signature: (I)Ljava/nio/ByteBuffer; */ JNIEXPORT jobject JNICALL Java_org_apache_mina_jni_ByteBufferAllocator__1allocate (JNIEnv *env, jclass class, jint capacity) { void* region = malloc((size_t) capacity); if (region == NULL) { return NULL; } return (*env)->NewDirectByteBuffer(env, region, capacity); } /* * Class: org_apache_mina_jni_ByteBufferAllocator * Method: _map * Signature: (JI)Ljava/nio/ByteBuffer; */ JNIEXPORT jobject JNICALL Java_org_apache_mina_jni_ByteBufferAllocator__1map (JNIEnv *env, jclass class, jlong address, jint capacity) { return (*env)->NewDirectByteBuffer(env, (void*) address, (jlong) capacity); } /* * Class: org_apache_mina_jni_ByteBufferAllocator * Method: _address * Signature: (Ljava/nio/ByteBuffer;)J */ JNIEXPORT jlong JNICALL Java_org_apache_mina_jni_ByteBufferAllocator__1address (JNIEnv *env, jclass class, jobject buffer) { return (jlong) (*env)->GetDirectBufferAddress(env, buffer); } /* * Class: org_apache_mina_jni_ByteBufferAllocator * Method: _deallocate * Signature: (J)V */ JNIEXPORT void JNICALL Java_org_apache_mina_jni_ByteBufferAllocator__1deallocate (JNIEnv *env, jclass class, jlong address) { free((void*) address); }