Reorder fbjni/ByteBuffer.cpp
Summary:
An upcoming diff will move some functions from JByteBuffer to JBuffer,
so putting wrapBytes last will improve readability.
@@ -34,21 +34,6 @@ void JBuffer::rewind() const {
meth(self());
}
-local_ref<JByteBuffer> JByteBuffer::wrapBytes(uint8_t* data, size_t size) {
- // env->NewDirectByteBuffer requires that size is positive. Android's
- // dalvik returns an invalid result and Android's art aborts if size == 0.
- // Workaround this by using a slow path through Java in that case.
- if (!size) {
- return createEmpty();
- }
- auto res = adopt_local(static_cast<javaobject>(Environment::current()->NewDirectByteBuffer(data, size)));
- FACEBOOK_JNI_THROW_PENDING_EXCEPTION();
- if (!res) {
- throw std::runtime_error("Direct byte buffers are unsupported.");
- }
- return res;
-}
-
uint8_t* JByteBuffer::getDirectBytes() const {
if (!self()) {
throwNewJavaException("java/lang/NullPointerException", "java.lang.NullPointerException");
@@ -84,4 +69,19 @@ bool JByteBuffer::isDirect() const {
return meth(self());
}
+local_ref<JByteBuffer> JByteBuffer::wrapBytes(uint8_t* data, size_t size) {
+ // env->NewDirectByteBuffer requires that size is positive. Android's
+ // dalvik returns an invalid result and Android's art aborts if size == 0.
+ // Workaround this by using a slow path through Java in that case.
+ if (!size) {
+ return createEmpty();
+ }
+ auto res = adopt_local(static_cast<javaobject>(Environment::current()->NewDirectByteBuffer(data, size)));
+ FACEBOOK_JNI_THROW_PENDING_EXCEPTION();
+ if (!res) {
+ throw std::runtime_error("Direct byte buffers are unsupported.");
+ }
+ return res;
+}
+
}}
