void Realm::write_copy(StringData path, BinaryData key) { REALM_ASSERT(!key.data() || key.size() == 64); verify_thread(); try { read_group()->write(path, key.data()); } catch (...) { translate_file_exception(path); } }
void Realm::write_copy(StringData path, BinaryData key) { if (key.data() && key.size() != 64) { throw InvalidEncryptionKeyException(); } verify_thread(); try { read_group().write(path, key.data()); } catch (...) { translate_file_exception(path); } }
inline size_t ChangesetInputStream::next_block(const char*& begin, const char*& end) { for (;;) { if (REALM_UNLIKELY(m_changesets_begin == m_changesets_end)) { if (m_begin_version == m_end_version) return 0; // End of input version_type n = sizeof m_changesets / sizeof m_changesets[0]; version_type avail = m_end_version - m_begin_version; if (n > avail) n = avail; version_type end_version = m_begin_version + n; m_history.get_changesets(m_begin_version, end_version, m_changesets); m_begin_version = end_version; m_changesets_begin = m_changesets; m_changesets_end = m_changesets_begin + n; } BinaryData changeset = *m_changesets_begin++; if (changeset.size() > 0) { begin = changeset.data(); end = changeset.data() + changeset.size(); return changeset.size(); } } }
bool next_block(const char*& begin, const char*& end) override { BinaryData block = m_it.get_next(); begin = block.data(); end = begin + block.size(); return begin != end; }
OwnedBinaryData Realm::write_copy() { verify_thread(); BinaryData buffer = read_group().write_to_mem(); // Since OwnedBinaryData does not have a constructor directly taking // ownership of BinaryData, we have to do this to avoid copying the buffer return OwnedBinaryData(std::unique_ptr<char[]>((char*)buffer.data()), buffer.size()); }
bool next_block(const char*& begin, const char*& end) override { while (m_valid) { BinaryData actual = m_changesets_begin->get_next(); if (actual.size() > 0) { begin = actual.data(); end = actual.data() + actual.size(); return true; } m_changesets_begin++; if (REALM_UNLIKELY(m_changesets_begin == m_changesets_end)) { get_changeset(); } } return false; // End of input }
REALM_EXPORT size_t object_get_binary(const Object& object, size_t property_ndx, const char*& return_buffer, size_t& return_size, NativeException::Marshallable& ex) { return handle_errors(ex, [&]() { verify_can_get(object); const size_t column_ndx = get_column_index(object, property_ndx); const BinaryData fielddata = object.row().get_binary(column_ndx); if (fielddata.is_null()) return 0; return_buffer = fielddata.data(); return_size = fielddata.size(); return 1; }); }
jbyteArray tbl_GetByteArray(JNIEnv* env, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) { if (!TBL_AND_INDEX_VALID(env, reinterpret_cast<T*>(nativeTablePtr), columnIndex, rowIndex)) return NULL; BinaryData bin = reinterpret_cast<T*>(nativeTablePtr)->get_binary( S(columnIndex), S(rowIndex)); if (bin.size() <= MAX_JSIZE) { jbyteArray jresult = env->NewByteArray(static_cast<jsize>(bin.size())); if (jresult) env->SetByteArrayRegion(jresult, 0, static_cast<jsize>(bin.size()), reinterpret_cast<const jbyte*>(bin.data())); // throws return jresult; } else { ThrowException(env, IllegalArgument, "Length of ByteArray is larger than an Int."); return NULL; } }
inline StringData BinaryColumn::get_string(size_t ndx) const noexcept { BinaryData bin = get(ndx); REALM_ASSERT_3(0, <, bin.size()); return StringData(bin.data(), bin.size()-1); }
jobject CreateJMixedFromMixed(JNIEnv* env, Mixed& mixed) { jclass jMixedClass = GetClassMixed(env); if (jMixedClass == NULL) return NULL; TR((env, "CreateJMixedFromMixed(type %d)\n", mixed.get_type())); switch (mixed.get_type()) { case type_Int: { jmethodID consId = GetMixedMethodID(env, "<init>", "(J)V"); if (consId) return env->NewObject(jMixedClass, consId, mixed.get_int()); } case type_Float: { jmethodID consId = GetMixedMethodID(env, "<init>", "(F)V"); if (consId) return env->NewObject(jMixedClass, consId, mixed.get_float()); } case type_Double: { jmethodID consId = GetMixedMethodID(env, "<init>", "(D)V"); if (consId) return env->NewObject(jMixedClass, consId, mixed.get_double()); } case type_String: { jmethodID consId = GetMixedMethodID(env, "<init>", "(Ljava/lang/String;)V"); if (consId) return env->NewObject(jMixedClass, consId, to_jstring(env, mixed.get_string())); } case type_Bool: { jmethodID consId = GetMixedMethodID(env, "<init>", "(Z)V"); if (consId) return env->NewObject(jMixedClass, consId, mixed.get_bool()); } case type_DateTime: { time_t timeValue = mixed.get_datetime().get_datetime(); jclass jDateClass = env->FindClass("java/util/Date"); if (jDateClass == NULL) { ThrowException(env, ClassNotFound, "Date"); return NULL; } jmethodID jDateConsId = env->GetMethodID(jDateClass, "<init>", "(J)V"); if (jDateConsId == NULL) { ThrowException(env, NoSuchMethod, "Date", "<init>"); return NULL; } jobject jDate = env->NewObject(jDateClass, jDateConsId, static_cast<jlong>(timeValue)); jmethodID consId = GetMixedMethodID(env, "<init>", "(Ljava/util/Date;)V"); if (consId) return env->NewObject(jMixedClass, consId, jDate); } case type_Binary: { BinaryData binaryData = mixed.get_binary(); jmethodID consId = GetMixedMethodID(env, "<init>", "(Ljava/nio/ByteBuffer;)V"); if (consId) { jobject jByteBuffer = env->NewDirectByteBuffer(const_cast<char*>(binaryData.data()), binaryData.size()); return env->NewObject(jMixedClass, consId, jByteBuffer); } } case type_Table: { // param input: Table* t. TR((env, " --Mixed(type_Table)\n")); jmethodID consId = GetMixedMethodID(env, "<init>", "(Lio/realm/internal/ColumnType;)V"); jobject jColumnType = NULL; // GetJColumnTypeFromColumnType(env, type_Table); if (consId) return env->NewObject(jMixedClass, consId, jColumnType); } case type_Mixed: break; case type_Link: break; case type_LinkList: break; } return NULL; }