Add `JByteBuffer::rewind()`

Summary:
Adds a `rewind()` method to `JByteBuffer`, which maps to `java.nio.Buffer#rewind()`.
This is useful if a `ByteBuffer` is reused for calls between Java and C++.

Differential Revision: D7435171

fbshipit-source-id: 488131d6ad2d5abb1b86a5efabc2f39ba0ab16cd
This commit is contained in:
David Aurelio 2018-03-29 05:24:29 -07:00 committed by Facebook Github Bot
parent e88f128608
commit ff2260b022
2 changed files with 12 additions and 0 deletions

View File

@ -15,6 +15,13 @@
namespace facebook {
namespace jni {
class JBuffer : public JavaClass<JBuffer> {
public:
static constexpr const char* kJavaDescriptor = "Ljava/nio/Buffer;";
void rewind() const;
};
// JNI's NIO support has some awkward preconditions and error reporting. This
// class provides much more user-friendly access.
class FBEXPORT JByteBuffer : public JavaClass<JByteBuffer> {

View File

@ -22,6 +22,11 @@ local_ref<JByteBuffer> createEmpty() {
}
}
void JBuffer::rewind() const {
static auto meth = javaClassStatic()->getMethod<alias_ref<JBuffer>()>("rewind");
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.