Commit a184eae8 authored by Jørgen Lind's avatar Jørgen Lind
Browse files

Merge branch feature/camille.perin/java-binding with refs/heads/master into...

Merge branch feature/camille.perin/java-binding with refs/heads/master into refs/merge-requests/130/train
parents 84f10bdb 4b8efeff
Pipeline #1545 passed with stages
in 2 minutes and 50 seconds
......@@ -17,3 +17,6 @@ python/tools/WrapperReport.txt
/**/aws_sdk*.log
/**/.ipynb_checkpoints
/python/openvds.egg-info
.idea
java/cpp/generated
cmake-build*
......@@ -32,6 +32,10 @@ function(Fetch3rdParty)
Fetch3rdParty_Package(curl 7.68.0 https://github.com/curl/curl/releases/download/curl-7_68_0/curl-7.68.0.tar.gz SHA256=1dd7604e418b0b9a9077f62f763f6684c1b092a7bc17e3f354b8ad5c964d7358)
Fetch3rdParty_Package(libuv 1.34.1 https://github.com/libuv/libuv/archive/v1.34.1.tar.gz SHA256=e3e0105c9b26e181e0547607cb6893462beb0c652674c3795766b2e5555288b3)
# if (BUILD_JAVA)
# Fetch3rdParty_Package(junit4 4.13.0 https://github.com/junit-team/junit4/archive/r4.13.tar.gz SHA256=c4e8f5681ad387a386a5aebe05ed4b73ffbfff963e154fbc4d77090f230777c7)
# endif()
if (BUILD_ZLIB)
Fetch3rdParty_Package(zlib 1.2.11 http://zlib.net/zlib-1.2.11.tar.gz SHA256=c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1)
endif()
......
......@@ -20,6 +20,7 @@ set (TEST_AZURE_CONNECTION "" CACHE STRING "Test Azure connection string")
set (OPENVDS_LIBDIR_SUFFIX "" CACHE STRING "Suffix to add to lib directories on linux")
set (OPENVDS_PYTHON_VERSION "" CACHE STRING "Exact Python 3 version to discover")
set (OPENVDS_JAVA_VERSION "" CACHE STRING "Exact Java version to discover")
option(FORCE_NO_LIBDIR_SUFFIX "Force there to be no suffix on lib directories linux")
get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
......@@ -48,6 +49,21 @@ else()
set(BUILD_PYTHON_DEFAULT OFF)
endif()
if (OPENVDS_JAVA_VERSION)
find_package(Java ${OPENVDS_JAVA_VERSION} COMPONENTS Development)
find_package(JNI)
else()
find_package(Java 1.8 COMPONENTS Development)
find_package(JNI)
endif()
if (Java_FOUND AND JNI_FOUND)
set(BUILD_JAVA_DEFAULT ON)
else()
message("Failed to find Java compiler. Disabling Java build")
set(BUILD_JAVA_DEFAULT OFF)
endif()
if (WIN32)
set(DEFAULT_BUILD_ZLIB ON)
set(DEFAULT_BUILD_CURL ON)
......@@ -59,6 +75,7 @@ else()
endif()
option(BUILD_PYTHON "Build python bindings" ${BUILD_PYTHON_DEFAULT})
option(BUILD_JAVA "Build java bindings" ${BUILD_JAVA_DEFAULT})
option(ENABLE_OPENMP "Enable the OpenMP codepath" ON)
option(BUILD_SHARED_LIBS "Build OpenVDS as a shared library" ON)
option(BUILD_EXAMPLES "Build OpenVDS example projects" ON)
......@@ -120,6 +137,10 @@ if (BUILD_PYTHON)
add_subdirectory(python)
endif ()
if (BUILD_JAVA)
add_subdirectory(java)
endif()
if (BUILD_DOCS)
add_subdirectory(docs)
endif()
......
FROM alpine:latest
# Install the various required packages
RUN apk add python3 python3-dev gcc g++ cmake make ninja git ccache doxygen \
RUN apk add python3 python3-dev gcc g++ cmake make ninja git ccache doxygen openjdk8 \
libxml2-dev boost-dev zlib-dev openssl-dev curl-dev libuv-dev \
util-linux-dev # This package contains the uuid development headers
......
......@@ -236,7 +236,7 @@ int main(int argc, char **argv)
bool finished = accessManager->WaitForCompletion(request);
if (!finished)
{
fmt::print(stderr, "Failed to download reuqest. Failing\n");
fmt::print(stderr, "Failed to download request. Failing\n");
return -2;
}
......
include(UseJava)
set(OPENVDS_JAVA_VERSION 0.0.6)
set(CPP_LIBRARY_NAME openvdsjava)
set(JAVA_LIBRARY_NAME openvds-java)
set(JAVA_LIBRARY_DOC_NAME openvds-java-javadoc)
set(GENERATED_HEADER_TARGET_NAME generatedHeadersTarget)
set(JAVA_TEST_ENABLED ON)
if(JAVA_TEST_ENABLED)
set(JAVA_TEST_LIBRARY_NAME openvds-java-test)
endif()
#set(CMAKE_JAVA_COMPILE_FLAGS "-source" "1.8" "-target" "1.8")
set(GENERATED_JNI_HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cpp/generated)
#file(REMOVE_RECURSE ${GENERATED_JNI_HEADERS_DIR})
file(MAKE_DIRECTORY ${GENERATED_JNI_HEADERS_DIR})
set(JAVA_SOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/java/src)
set(JAVA_DEMO_SOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/java/demo)
set(JAVA_EXPERIMENTAL_SOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/java/experimental)
if(JAVA_TEST_ENABLED)
set(JAVA_TEST_SOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/java/test)
endif()
file (GLOB_RECURSE JAVA_SOURCES_FILES CONFIGURE_DEPENDS
${JAVA_SOURCES_DIR}/*.java
${JAVA_DEMO_SOURCES_DIR}/*.java
# ${JAVA_EXPERIMENTAL_SOURCES_DIR}/*.java
)
if(JAVA_TEST_ENABLED)
file (GLOB_RECURSE JAVA_TEST_SOURCES_FILES CONFIGURE_DEPENDS
${JAVA_TEST_SOURCES_DIR}/*.java)
endif()
message(STATUS "Compiling Java files")
foreach(FILE ${JAVA_SOURCES_FILES})
message(STATUS ${FILE})
endforeach()
if(JAVA_TEST_ENABLED)
foreach(FILE ${JAVA_TEST_SOURCES_FILES})
message(STATUS ${FILE})
endforeach()
endif()
# Java compilation
# Enable JNI header generation for java >=8
if (WIN32)
add_jar(${JAVA_LIBRARY_NAME}
SOURCES ${JAVA_SOURCES_FILES}
GENERATE_NATIVE_HEADERS ${GENERATED_HEADER_TARGET_NAME} DESTINATION ${GENERATED_JNI_HEADERS_DIR}
ENTRY_POINT OpenVdsDemo)
else()
add_jar(${JAVA_LIBRARY_NAME}
SOURCES ${JAVA_SOURCES_FILES}
VERSION ${OPENVDS_JAVA_VERSION}
GENERATE_NATIVE_HEADERS ${GENERATED_HEADER_TARGET_NAME} DESTINATION ${GENERATED_JNI_HEADERS_DIR}
ENTRY_POINT OpenVdsDemo)
endif()
create_javadoc(${JAVA_LIBRARY_DOC_NAME}
FILES ${JAVA_SOURCES_FILES}
# CLASSPATH ${CMAKE_JAVA_INCLUDE_PATH}
WINDOWTITLE "OpenVDS-Java"
DOCTITLE "<h1>OpenVDS-Java</h1>"
AUTHOR TRUE
USE TRUE
VERSION TRUE)
if(JAVA_TEST_ENABLED)
get_property(BUILT_JAR_FILE TARGET ${JAVA_LIBRARY_NAME} PROPERTY JAR_FILE)
message(STATUS "Found built library :" ${BUILT_JAR_FILE})
file(DOWNLOAD https://repo1.maven.org/maven2/org/testng/testng/6.14.3/testng-6.14.3.jar
${CMAKE_CURRENT_BINARY_DIR}/testng-6.14.3.jar
SHOW_PROGRESS
EXPECTED_HASH MD5=9f17a8f9e99165e148c42b21f4b63d7c)
add_jar(${JAVA_TEST_LIBRARY_NAME}
SOURCES ${JAVA_TEST_SOURCES_FILES}
INCLUDE_JARS
${CMAKE_CURRENT_BINARY_DIR}/testng-6.14.3.jar
${BUILT_JAR_FILE}
VERSION ${OPENVDS_JAVA_VERSION})
endif()
# C++ compilation
file (GLOB_RECURSE CPP_SOURCES_FILES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cpp/src/*.cpp)
message(STATUS "Compiling cpp")
foreach(FILE ${CPP_SOURCES_FILES})
message(STATUS ${FILE})
endforeach()
add_library(${CPP_LIBRARY_NAME} ${CPP_SOURCES_FILES})
set_target_properties(${CPP_LIBRARY_NAME} PROPERTIES FOLDER java)
set_target_properties(${CPP_LIBRARY_NAME} PROPERTIES VERSION ${OPENVDS_JAVA_VERSION})
copyDllForTarget(${CPP_LIBRARY_NAME})
target_include_directories(${CPP_LIBRARY_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/include)
target_include_directories(${CPP_LIBRARY_NAME} PUBLIC ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
target_link_libraries(${CPP_LIBRARY_NAME} PRIVATE openvds ${GENERATED_HEADER_TARGET_NAME})
# Install jar and natives
install(TARGETS ${CPP_LIBRARY_NAME} LIBRARY DESTINATION java)
install_jar(${JAVA_LIBRARY_NAME} DESTINATION java)
if(JAVA_TEST_ENABLED)
install_jar(${JAVA_TEST_LIBRARY_NAME} DESTINATION java)
endif()
## OpenVDS Java bindings
This readme file is meant to help developers who want to build and use the OpenVDS java bindings
### Dependencies
This module depends on
- Java 1.8+
- TestNG (to compile and execute unit tests)
### Build
By default OpenVDS builds the Java bindings.
To disable building the Java bindings use the -DBUILD_JAVA=OFF cmake argument.
### Supported platform and compiler
- Redhat/Centos 8+
- java >= 1.8 openjdk/oracle
TEMPLATE = lib
CONFIG *= debug_and_release shared thread rtti warn_on static_runtime
CONFIG -= qt
QT -= core gui
TARGET = OpenVdsJni
VDS = C:/INT/OpenVDS/open-vds-master
INCLUDEPATH += include $$(VDS)/src/OpenVDS $$(VDS)/3rdparty/fmt-6.0.0/include
LIBS *= \
$$(VDS)\src\OpenVDS\Debug\openvds.lib \
$$(VDS)\aws-cpp-sdk_1.7.282_install\Debug\bin\aws-cpp-sdk-core.lib \
$$(VDS)\aws-cpp-sdk_1.7.282_install\Debug\bin\aws-cpp-sdk-s3.lib \
$$(VDS)\aws-cpp-sdk_1.7.282_install\Debug\bin\aws-cpp-sdk-sts.lib \
$$(VDS)\azure-storage_7.0.0_install\Debug\lib\wastorage.lib \
$$(VDS)\cpp-rest-api_2.10.14_install\Debug\lib\cpprest140_2_10d.lib \
$$(VDS)\fmt_6.0.0\Debug\fmtd.lib \
$$(VDS)\zlib_1.2.11_install\Debug\lib\zlibd.lib \
winhttp.lib
win32*-g++* {
# Uncomment flags below (function names decoration) if dll is loaded from Java for Windows
#QMAKE_LFLAGS *= -Wl,--subsystem,windows,--kill-at
}
# compile with OpenMP support
win32*-msvc* {
QMAKE_CXXFLAGS *= /openmp
}
win32*-g++* | linux-g++* {
QMAKE_CXXFLAGS *= -fopenmp
LIBS *= -lgomp -lpthread
QMAKE_LFLAGS += -Wl,-z,defs
}
linux-icc* {
QMAKE_CXXFLAGS *= -qopenmp
LIBS *= -liomp5
QMAKE_LFLAGS += -Wl,-z,defs
}
ENV_JAVA_HOME = $$(JAVA_HOME)
isEmpty(ENV_JAVA_HOME) {
error("You should define $JAVA_HOME environment variable. Specifically, the <javah> Java utility expected to be found in $JAVA_HOME/bin")
}
INCLUDEPATH += "$$(JAVA_HOME)/include"
win32 {
INCLUDEPATH += "$$(JAVA_HOME)/include/win32"
}
unix {
INCLUDEPATH += "$$(JAVA_HOME)/include/linux"
}
macx {
INCLUDEPATH += "$$(JAVA_HOME)/include/darwin"
}
HEADERS += \
include/Common.h \
include/CommonJni.h \
include/Portability.h \
include/org_opengroup_openvds_JniPointer.h \
include/org_opengroup_openvds_MemoryVdsGenerator.h \
include/org_opengroup_openvds_MetadataReadAccess.h \
include/org_opengroup_openvds_NativeBuffer.h \
include/org_opengroup_openvds_QuantizingValueConverter_FloatToByte.h \
include/org_opengroup_openvds_VdsHandle.h \
include/org_opengroup_openvds_VolumeDataAccessManager.h \
include/org_opengroup_openvds_VolumeDataAccessor.h \
include/org_opengroup_openvds_VolumeDataLayout.h \
include/org_opengroup_openvds_VolumeDataPage.h \
include/org_opengroup_openvds_VolumeDataPageAccessor.h \
SOURCES += \
src/Common.cpp \
src/CommonJni.cpp \
src/JniPointer.cpp \
src/MemoryVdsGenerator.cpp \
src/MetadataReadAccess.cpp \
src/NativeBuffer.cpp \
src/QuantizingValueConverter_FloatToByte.cpp \
src/VdsHandle.cpp \
src/VolumeDataAccessManager.cpp \
src/VolumeDataAccessor.cpp \
src/VolumeDataLayout.cpp \
src/VolumeDataPage.cpp \
src/VolumeDataPageAccessor.cpp \
/*
* Copyright 2019 The Open Group
* Copyright 2019 INT, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _COMMON_H_
#define _COMMON_H_
#include <cstddef>
void ThrowCppException( const char* format, ... );
#endif
/*
* Copyright 2019 The Open Group
* Copyright 2019 INT, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _COMMONJNI_H_
#define _COMMONJNI_H_
#include <jni.h>
#include <string>
#include <vector>
extern const char StringClassId[], ExceptionClassId[], IOExceptionClassId[];
void* CheckHandle( jlong handle );
void ThrowJavaIOException( JNIEnv *env, const char* message);
void ThrowJavaException( JNIEnv *env, const char* format, ... );
void ThrowJavaExceptionUnknown( JNIEnv *env );
#define CATCH_EXCEPTIONS_FOR_JAVA \
catch( const std::exception& se ) { ThrowJavaException( env, se.what() ); } \
catch( ... ) { ThrowJavaExceptionUnknown( env ); }
std::string JStringToString( JNIEnv* env, jstring jstr );
std::vector<char> JArrayToVector( JNIEnv* env, jbyteArray jArr );
std::vector<char> JArrayToVector( JNIEnv* env, jbyteArray jArr, int start, int len );
std::vector<short> JArrayToVector( JNIEnv* env, jshortArray jArr );
std::vector<int> JArrayToVector( JNIEnv* env, jintArray jArr );
std::vector<float> JArrayToVector( JNIEnv* env, jfloatArray jArr );
jbyteArray NewJByteArray( JNIEnv* env, const std::string& str );
jstring NewJString( JNIEnv* env, const char* str );
jstring NewJString( JNIEnv* env, const std::string& str );
jobjectArray NewJStringArray( JNIEnv* env, const std::string* strings, size_t nStrings );
jobjectArray NewJStringArray( JNIEnv* env, const std::vector<std::string>& strings );
jbyteArray NewJByteArray( JNIEnv* env, const char* data, size_t count );
jshortArray NewJShortArray( JNIEnv* env, const short* data, size_t count );
jintArray NewJIntArray( JNIEnv* env, const int* data, size_t count );
jlongArray NewJLongArray( JNIEnv* env, const int64_t* data, size_t count );
jfloatArray NewJFloatArray( JNIEnv* env, const float* data, size_t count );
jdoubleArray NewJDoubleArray( JNIEnv* env, const double* data, size_t count );
#endif
\ No newline at end of file
/*
* Copyright 2019 The Open Group
* Copyright 2019 INT, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define __PLATFORM_SparcCompiler 0
#define __PLATFORM_SparcGcc 1
#define __PLATFORM_EgcsLinux 2
#define __PLATFORM_Win32MSVC 3
#define __PLATFORM_Win32MinGW 4
#define __PLATFORM_SgiCompiler 5
#define __PLATFORM_IbmCompiler 6
#define __PLATFORM_HpCompiler 7
#define __PLATFORM_LinuxIcc 8
#define __PLATFORM_MacIcc 9
#ifndef __PLATFORM
#if defined(__SUNPRO_CC)
#define __PLATFORM __PLATFORM_SparcCompiler
#define __PLATFORM_NAME SparcCompiler
#elif defined(__INTEL_COMPILER)
#if defined(__linux__)
#define __PLATFORM __PLATFORM_LinuxIcc
#define __PLATFORM_NAME LinuxIcc
#else
#define __PLATFORM __PLATFORM_MacxIcc
#define __PLATFORM_NAME MacIcc
#endif
#elif defined(__GNUC__)
#if defined(__sparc__)
#define __PLATFORM __PLATFORM_SparcGcc
#define __PLATFORM_NAME SparcGcc
#elif defined(__linux__)
#define __PLATFORM __PLATFORM_EgcsLinux
#define __PLATFORM_NAME EgcsLinux
#elif defined(_WIN32)
#define __PLATFORM __PLATFORM_Win32MinGW
#define __PLATFORM_NAME Win32-MinGW
#elif defined(__APPLE__)
#define __PLATFORM __PLATFORM_MacClang
#define __PLATFORM_NAME MacClang
#elif defined(__EMSCRIPTEN__)
#define __PLATFORM __PLATFORM_Emscripten
#define __PLATFORM_NAME Emscripten
#else
#error Unsupported platform for GNU C++ Compiler!
#endif
#elif defined(_MSC_VER)
#define __PLATFORM __PLATFORM_Win32MSVC
#define __PLATFORM_NAME Win32-MSVC
#elif defined(__sgi)
#define __PLATFORM __PLATFORM_SgiCompiler
#define __PLATFORM_NAME SgiCompiler
#elif defined(_AIX)
#define __PLATFORM __PLATFORM_IbmCompiler
#define __PLATFORM_NAME IbmCompiler
#elif defined(__hpux)
#define __PLATFORM __PLATFORM_HpCompiler
#define __PLATFORM_NAME HpCompiler
#else
#error Unknown platform!
#endif
#endif
/*
* Copyright 2019 The Open Group
* Copyright 2019 INT, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <Common.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdexcept>
#include <cstring>
void ThrowCppException( const char* format, ... ) {
if( strchr( format, '%' ) ) {
static char buf[1000];
va_list arg;
va_start( arg, format );
vsnprintf( buf, sizeof( buf ), format, arg );
buf[sizeof( buf ) - 1] = 0;
format = buf;
}
throw std::runtime_error( format );
}
/*
* Copyright 2019 The Open Group
* Copyright 2019 INT, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "Common.h"
#include "CommonJni.h"
#include <assert.h>
#include <exception>
#include <cstring>
const char
StringClassId[] = "Ljava/lang/String;",
ExceptionClassId[] = "java/lang/Exception",
IOExceptionClassId[] = "java/io/IOException";
void* CheckHandle( jlong handle ) {
if( !handle )
ThrowCppException( "Handle is NULL" );
return (void*)handle;
}
void ThrowJavaIOException( JNIEnv *env, const char* message) {
env->ThrowNew( env->FindClass( IOExceptionClassId ), message );
}
void ThrowJavaException( JNIEnv *env, const char* format, ... ) {
if( strchr( format, '%' ) ) {
char buf[1000];
va_list arg;
va_start( arg, format );
vsnprintf( buf, sizeof( buf ), format, arg );
buf[sizeof( buf ) - 1] = 0;
format = buf;
}
env->ThrowNew( env->FindClass( ExceptionClassId ), format );
}
void ThrowJavaExceptionUnknown( JNIEnv *env ) {
env->ThrowNew( env->FindClass( ExceptionClassId ), "Unknown exception occured in C++ code" );
}
std::string JStringToString( JNIEnv* env, jstring jStr )
{
if( jStr == NULL )
return std::string();
const char* chars = (env)->GetStringUTFChars( jStr, 0 );
std::string str( chars );
env->ReleaseStringUTFChars( jStr, chars );
return str;
}
std::vector<char> JArrayToVector( JNIEnv* env, jbyteArray jArr ) {
if( !jArr )
return std::vector<char>();
if( sizeof( jbyte ) != sizeof( char ) )
ThrowJavaException( env, "sizeof(jbyte)!=sizeof(char)" );
jsize len = env->GetArrayLength( jArr );
std::vector<char> arr( len );
env->GetByteArrayRegion( jArr, 0, len, (jbyte*)arr.data() );
return arr;
}
std::vector<char> JArrayToVector( JNIEnv* env, jbyteArray jArr, int start, int len ) {
if( !jArr )
return std::vector<char>();
if( sizeof( jbyte ) != sizeof( char ) )
ThrowJavaException( env, "sizeof(jbyte)!=sizeof(char)" );
std::vector<char> arr( len );
env->GetByteArrayRegion( jArr, start, len, (jbyte*)arr.data() );
return arr;
}
std::vector<short> JArrayToVector( JNIEnv* env, jshortArray jArr ) {
if( !jArr )
return std::vector<short>();
if( sizeof( jshort ) != sizeof( short ) )
ThrowJavaException( env, "sizeof(jshort)!=sizeof(short)" );
jsize len = env->GetArrayLength( jArr );
std::vector<short> arr( len );
env->GetShortArrayRegion( jArr, 0, len, (jshort*)arr.data() );
return arr;
}
std::vector<int> JArrayToVector( JNIEnv* env, jintArray jArr ) {
if( !jArr )
return std::vector<int>();
if( sizeof( jint ) != sizeof( int ) )
ThrowJavaException( env, "sizeof(jint)!=sizeof(int)" );
jsize len = env->GetArrayLength( jArr );