From 550339c71b8d647cf63e6282a961caff9887f9d7 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Thu, 29 Mar 2018 22:48:44 -0700 Subject: [PATCH] Add `JReadableByteChannel` Summary: Adds `JReadableByteChannel`, which maps to `java.nio.ReadableByteChannel`. This class is useful to stream data from Java to C++ memory (in conjunction with `JByteBuffer`). Differential Revision: D7437312 fbshipit-source-id: 4979706148f0e20228f0f52341fb340497c24a8b --- .../src/main/jni/first-party/fb/Android.mk | 1 + .../fb/include/fb/fbjni/ReadableByteChannel.h | 23 +++++++++++++++++++ .../fb/jni/ReadableByteChannel.cpp | 21 +++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 ReactAndroid/src/main/jni/first-party/fb/include/fb/fbjni/ReadableByteChannel.h create mode 100644 ReactAndroid/src/main/jni/first-party/fb/jni/ReadableByteChannel.cpp diff --git a/ReactAndroid/src/main/jni/first-party/fb/Android.mk b/ReactAndroid/src/main/jni/first-party/fb/Android.mk index aaf198bce..4540eef1d 100644 --- a/ReactAndroid/src/main/jni/first-party/fb/Android.mk +++ b/ReactAndroid/src/main/jni/first-party/fb/Android.mk @@ -13,6 +13,7 @@ LOCAL_SRC_FILES:= \ jni/jni_helpers.cpp \ jni/LocalString.cpp \ jni/OnLoad.cpp \ + jni/ReadableByteChannel.cpp \ jni/References.cpp \ jni/WeakReference.cpp \ log.cpp \ diff --git a/ReactAndroid/src/main/jni/first-party/fb/include/fb/fbjni/ReadableByteChannel.h b/ReactAndroid/src/main/jni/first-party/fb/include/fb/fbjni/ReadableByteChannel.h new file mode 100644 index 000000000..f895a3e6f --- /dev/null +++ b/ReactAndroid/src/main/jni/first-party/fb/include/fb/fbjni/ReadableByteChannel.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2016-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +namespace facebook { +namespace jni { + +class JReadableByteChannel : public JavaClass { +public: + static constexpr const char* kJavaDescriptor = "Ljava/nio/channels/ReadableByteChannel;"; + + int read(alias_ref dest) const; +}; + +}} diff --git a/ReactAndroid/src/main/jni/first-party/fb/jni/ReadableByteChannel.cpp b/ReactAndroid/src/main/jni/first-party/fb/jni/ReadableByteChannel.cpp new file mode 100644 index 000000000..9c67df3fa --- /dev/null +++ b/ReactAndroid/src/main/jni/first-party/fb/jni/ReadableByteChannel.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2016-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +namespace facebook { +namespace jni { + +int JReadableByteChannel::read(alias_ref dest) const { + if (!self()) { + throwNewJavaException("java/lang/NullPointerException", "java.lang.NullPointerException"); + } + static auto method = javaClassStatic()->getMethod)>("read"); + return method(self(), dest); +} + +}}