static jboolean putBlob_native(JNIEnv * env, jobject object, jbyteArray value, jint row, jint col) { CursorWindow * window = GET_WINDOW(env, object); if (!value) { LOG_WINDOW("How did a null value send to here"); return false; } field_slot_t * fieldSlot = window->getFieldSlotWithCheck(row, col); if (fieldSlot == NULL) { LOG_WINDOW(" getFieldSlotWithCheck error "); return false; } jint len = env->GetArrayLength(value); int offset = window->alloc(len); if (!offset) { LOG_WINDOW("Failed allocating %u bytes", len); return false; } jbyte * bytes = env->GetByteArrayElements(value, NULL); window->copyIn(offset, (uint8_t const *)bytes, len); // This must be updated after the call to alloc(), since that // may move the field around in the window fieldSlot->type = FIELD_TYPE_BLOB; fieldSlot->data.buffer.offset = offset; fieldSlot->data.buffer.size = len; env->ReleaseByteArrayElements(value, bytes, JNI_ABORT); LOG_WINDOW("%d,%d is BLOB with %u bytes @ %d", row, col, len, offset); return true; }
static jboolean putString_native(JNIEnv * env, jobject object, jstring value, jint row, jint col) { CursorWindow * window = GET_WINDOW(env, object); if (!value) { LOG_WINDOW("How did a null value send to here"); return false; } field_slot_t * fieldSlot = window->getFieldSlotWithCheck(row, col); if (fieldSlot == NULL) { LOG_WINDOW(" getFieldSlotWithCheck error "); return false; } #if WINDOW_STORAGE_UTF8 int len = env->GetStringUTFLength(value) + 1; char const * valStr = env->GetStringUTFChars(value, NULL); #else int len = env->GetStringLength(value); // GetStringLength return number of chars and one char takes 2 bytes len *= 2; const jchar* valStr = env->GetStringChars(value, NULL); #endif if (!valStr) { LOG_WINDOW("value can't be transfer to UTFChars"); return false; } int offset = window->alloc(len); if (!offset) { LOG_WINDOW("Failed allocating %u bytes", len); #if WINDOW_STORAGE_UTF8 env->ReleaseStringUTFChars(value, valStr); #else env->ReleaseStringChars(value, valStr); #endif return false; } window->copyIn(offset, (uint8_t const *)valStr, len); // This must be updated after the call to alloc(), since that // may move the field around in the window fieldSlot->type = FIELD_TYPE_STRING; fieldSlot->data.buffer.offset = offset; fieldSlot->data.buffer.size = len; LOG_WINDOW("%d,%d is TEXT with %u bytes @ %d", row, col, len, offset); #if WINDOW_STORAGE_UTF8 env->ReleaseStringUTFChars(value, valStr); #else env->ReleaseStringChars(value, valStr); #endif return true; }