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
This commit is contained in:
parent
1020ac9481
commit
550339c71b
|
@ -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 \
|
||||
|
|
|
@ -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 <fb/fbjni.h>
|
||||
#include <fb/fbjni/ByteBuffer.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace jni {
|
||||
|
||||
class JReadableByteChannel : public JavaClass<JReadableByteChannel> {
|
||||
public:
|
||||
static constexpr const char* kJavaDescriptor = "Ljava/nio/channels/ReadableByteChannel;";
|
||||
|
||||
int read(alias_ref<JByteBuffer> dest) const;
|
||||
};
|
||||
|
||||
}}
|
|
@ -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 <fb/fbjni/ReadableByteChannel.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace jni {
|
||||
|
||||
int JReadableByteChannel::read(alias_ref<JByteBuffer> dest) const {
|
||||
if (!self()) {
|
||||
throwNewJavaException("java/lang/NullPointerException", "java.lang.NullPointerException");
|
||||
}
|
||||
static auto method = javaClassStatic()->getMethod<jint(alias_ref<JByteBuffer>)>("read");
|
||||
return method(self(), dest);
|
||||
}
|
||||
|
||||
}}
|
Loading…
Reference in New Issue