summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorAllen Byrne <50328838+byrnHDF@users.noreply.github.com>2022-10-26 04:33:30 (GMT)
committerGitHub <noreply@github.com>2022-10-26 04:33:30 (GMT)
commit9c61f7b1e1cfb65cd562febfbb7ad49e8785825c (patch)
tree2bf6453021345ae6013d6181e6028f2ff41dd7cb /java
parentad2d77397ac564836f5fd89e66d5647250daf10e (diff)
downloadhdf5-9c61f7b1e1cfb65cd562febfbb7ad49e8785825c.zip
hdf5-9c61f7b1e1cfb65cd562febfbb7ad49e8785825c.tar.gz
hdf5-9c61f7b1e1cfb65cd562febfbb7ad49e8785825c.tar.bz2
JNI: Improve varlen datatype handling in H5A/H5D read/write functions (#2156)
* Improve JNI VL datatype read/write to handle complex combinations * Implement VL of VL JNI writes and reads * Add Java VLofVL test for attributtes * Changes to address review issues * Fix H5Aread vl blocks
Diffstat (limited to 'java')
-rw-r--r--java/src/jni/h5aImp.c572
-rw-r--r--java/src/jni/h5dImp.c547
-rw-r--r--java/src/jni/h5fImp.c4
-rw-r--r--java/src/jni/h5tImp.c4
-rw-r--r--java/src/jni/h5util.c545
-rw-r--r--java/src/jni/h5util.h5
-rw-r--r--java/test/TestH5A.java161
-rw-r--r--java/test/TestH5D.java181
-rw-r--r--java/test/TestH5R.java24
-rw-r--r--java/test/testfiles/JUnit-TestH5A.txt3
-rw-r--r--java/test/testfiles/JUnit-TestH5D.txt3
11 files changed, 1080 insertions, 969 deletions
diff --git a/java/src/jni/h5aImp.c b/java/src/jni/h5aImp.c
index 086fea8..4665376 100644
--- a/java/src/jni/h5aImp.c
+++ b/java/src/jni/h5aImp.c
@@ -156,13 +156,15 @@ JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Aread(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jbyteArray buf,
jboolean isCriticalPinning)
{
- jboolean readBufIsCopy;
- jbyte *readBuf = NULL;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n;
- htri_t vl_data_class;
- herr_t status = FAIL;
+ jboolean readBufIsCopy;
+ jbyte *readBuf = NULL;
+ hsize_t dims[H5S_MAX_RANK];
+ hid_t sid = H5I_INVALID_HID;
+ size_t typeSize;
+ H5T_class_t type_class;
+ jsize vl_array_len; // Only used by vl_data_class types
+ htri_t vl_data_class;
+ herr_t status = FAIL;
UNUSED(clss);
@@ -174,40 +176,60 @@ Java_hdf_hdf5lib_H5_H5Aread(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_t
if (vl_data_class) {
/* Get size of data array */
- if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
+ if ((vl_array_len = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0");
}
- dims[0] = (hsize_t)n;
- if ((sid = H5Screate_simple(1, dims, NULL)) < 0)
+ if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
- }
- if (isCriticalPinning) {
- PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy,
- "H5Aread: read buffer not critically pinned");
+ if (NULL == (readBuf = HDcalloc((size_t)vl_array_len, typeSize)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5Aread: failed to allocate raw VL read buffer");
}
else {
- PIN_BYTE_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread: read buffer not pinned");
+ if (isCriticalPinning) {
+ PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy,
+ "H5Aread: read buffer not critically pinned");
+ }
+ else {
+ PIN_BYTE_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread: read buffer not pinned");
+ }
}
if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, (void *)readBuf)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
+ if (vl_data_class) {
+ if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ translate_rbuf(env, buf, mem_type_id, type_class, vl_array_len, readBuf);
+ }
+
done:
if (readBuf) {
if ((status >= 0) && vl_data_class) {
+ dims[0] = (hsize_t)vl_array_len;
+ if ((sid = H5Screate_simple(1, dims, NULL)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
H5Treclaim(attr_id, sid, H5P_DEFAULT, readBuf);
+
if (sid >= 0)
H5Sclose(sid);
}
- if (isCriticalPinning) {
- UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
+ if (vl_data_class) {
+ HDfree(readBuf);
}
else {
- UNPIN_BYTE_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
+ if (isCriticalPinning) {
+ UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
+ }
+ else {
+ UNPIN_BYTE_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
+ }
}
}
@@ -223,38 +245,52 @@ JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Awrite(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jbyteArray buf,
jboolean isCriticalPinning)
{
- jboolean writeBufIsCopy;
- jbyte *writeBuf = NULL;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n;
- htri_t vl_data_class;
- herr_t status = FAIL;
+ jboolean writeBufIsCopy;
+ jbyte *writeBuf = NULL;
+ hsize_t dims[H5S_MAX_RANK];
+ hid_t sid = H5I_INVALID_HID;
+ size_t typeSize;
+ H5T_class_t type_class;
+ jsize vl_array_len; // Only used by vl_data_class types
+ htri_t vl_data_class;
+ herr_t status = FAIL;
UNUSED(clss);
if (NULL == buf)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite: write buffer is NULL");
- /* Get size of data array */
- if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
- H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0");
- }
-
- dims[0] = (hsize_t)n;
- if ((sid = H5Screate_simple(1, dims, NULL)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
-
if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
- if (isCriticalPinning) {
- PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy,
- "H5Awrite: write buffer not critically pinned");
+ if (vl_data_class) {
+ /* Get size of data array */
+ if ((vl_array_len = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite: write buffer length < 0");
+ }
+
+ if (!(typeSize = H5Tget_size(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ if (NULL == (writeBuf = HDcalloc((size_t)vl_array_len, typeSize)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5Awrite: failed to allocate raw VL write buffer");
}
else {
- PIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite: write buffer not pinned");
+ if (isCriticalPinning) {
+ PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy,
+ "H5Awrite: write buffer not critically pinned");
+ }
+ else {
+ PIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite: write buffer not pinned");
+ }
+ }
+
+ if (vl_data_class) {
+ if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ translate_wbuf(ENVONLY, buf, mem_type_id, type_class, vl_array_len, writeBuf);
}
if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, writeBuf)) < 0)
@@ -262,14 +298,24 @@ Java_hdf_hdf5lib_H5_H5Awrite(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_
done:
if (writeBuf) {
- if ((status >= 0) && vl_data_class)
+ if ((status >= 0) && vl_data_class) {
+ dims[0] = (hsize_t)vl_array_len;
+ if ((sid = H5Screate_simple(1, dims, NULL)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
H5Treclaim(attr_id, sid, H5P_DEFAULT, writeBuf);
+ }
- if (isCriticalPinning) {
- UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
+ if (vl_data_class) {
+ HDfree(writeBuf);
}
else {
- UNPIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
+ if (isCriticalPinning) {
+ UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
+ }
+ else {
+ UNPIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
+ }
}
}
@@ -1064,244 +1110,9 @@ done:
JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf)
{
- H5T_class_t type_class;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n = 0;
- htri_t vl_data_class;
- herr_t status = FAIL;
- jbyteArray *readBuf = NULL;
-
- UNUSED(clss);
-
- if (NULL == buf)
- H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5AreadVL: read buffer is NULL");
-
- if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
-
- if (vl_data_class) {
- /* Get size of data array */
- if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
- H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AreadVL: readBuf length < 0");
- }
-
- dims[0] = (hsize_t)n;
- if ((sid = H5Screate_simple(1, dims, NULL)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- }
-
- if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- if (type_class == H5T_VLEN) {
- size_t typeSize;
- hid_t memb = H5I_INVALID_HID;
- H5T_class_t vlClass;
- size_t vlSize;
- void *rawBuf = NULL;
- jobjectArray jList = NULL;
-
- size_t i, j, x;
-
- if (!(typeSize = H5Tget_size(mem_type_id)))
- H5_LIBRARY_ERROR(ENVONLY);
-
- if (!(memb = H5Tget_super(mem_type_id)))
- H5_LIBRARY_ERROR(ENVONLY);
- if ((vlClass = H5Tget_class((hid_t)memb)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- if (!(vlSize = H5Tget_size(memb)))
- H5_LIBRARY_ERROR(ENVONLY);
-
- if (NULL == (rawBuf = HDcalloc((size_t)n, typeSize)))
- H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5AreadVL: failed to allocate raw VL read buffer");
+ herr_t status = FAIL;
- if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, (void *)rawBuf)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
-
- /* Cache class types */
- /* jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean"); */
- jclass cByte = ENVPTR->FindClass(ENVONLY, "java/lang/Byte");
- jclass cShort = ENVPTR->FindClass(ENVONLY, "java/lang/Short");
- jclass cInt = ENVPTR->FindClass(ENVONLY, "java/lang/Integer");
- jclass cLong = ENVPTR->FindClass(ENVONLY, "java/lang/Long");
- jclass cFloat = ENVPTR->FindClass(ENVONLY, "java/lang/Float");
- jclass cDouble = ENVPTR->FindClass(ENVONLY, "java/lang/Double");
-
- /*
- jmethodID boolValueMid =
- ENVPTR->GetStaticMethodID(ENVONLY, cBool, "valueOf", "(Z)Ljava/lang/Boolean;");
- */
- jmethodID byteValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cByte, "valueOf", "(B)Ljava/lang/Byte;");
- jmethodID shortValueMid =
- ENVPTR->GetStaticMethodID(ENVONLY, cShort, "valueOf", "(S)Ljava/lang/Short;");
- jmethodID intValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cInt, "valueOf", "(I)Ljava/lang/Integer;");
- jmethodID longValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cLong, "valueOf", "(J)Ljava/lang/Long;");
- jmethodID floatValueMid =
- ENVPTR->GetStaticMethodID(ENVONLY, cFloat, "valueOf", "(F)Ljava/lang/Float;");
- jmethodID doubleValueMid =
- ENVPTR->GetStaticMethodID(ENVONLY, cDouble, "valueOf", "(D)Ljava/lang/Double;");
-
- // retrieve the java.util.List interface class
- jclass cList = ENVPTR->FindClass(ENVONLY, "java/util/List");
- jmethodID addMethod = ENVPTR->GetMethodID(ENVONLY, cList, "add", "(Ljava/lang/Object;)Z");
-
- /* Convert each element to a list */
- for (i = 0; i < (size_t)n; i++) {
- hvl_t vl_elem;
-
- // The list we're going to return:
- if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, (jsize)i)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
-
- /* Get the number of sequence elements */
- HDmemcpy(&vl_elem, (char *)rawBuf + i * typeSize, sizeof(hvl_t));
-
- jsize nelmts = (jsize)vl_elem.len;
- if (vl_elem.len != (size_t)nelmts)
- H5_JNI_FATAL_ERROR(ENVONLY, "H5AreadVL: overflow of number of VL elements");
- if (nelmts < 0)
- H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AreadVL: number of VL elements < 0");
-
- jobject jobj = NULL;
- for (j = 0; j < (size_t)nelmts; j++) {
- switch (vlClass) {
- /* case H5T_BOOL: {
- jboolean boolValue;
- for (x = 0; x < vlSize; x++) {
- ((char *)&boolValue)[x] = ((char *)vl_elem.p)[j*vlSize+x];
- }
-
- jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cBool, boolValueMid, boolValue);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- } */
- case H5T_INTEGER: {
- switch (vlSize) {
- case sizeof(jbyte): {
- jbyte byteValue;
- for (x = 0; x < vlSize; x++) {
- ((char *)&byteValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
- }
-
- jobj =
- ENVPTR->CallStaticObjectMethod(ENVONLY, cByte, byteValueMid, byteValue);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- case sizeof(jshort): {
- jshort shortValue;
- for (x = 0; x < vlSize; x++) {
- ((char *)&shortValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
- }
-
- jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cShort, shortValueMid,
- shortValue);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- case sizeof(jint): {
- jint intValue;
- for (x = 0; x < vlSize; x++) {
- ((char *)&intValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
- }
-
- jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cInt, intValueMid, intValue);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- case sizeof(jlong): {
- jlong longValue;
- for (x = 0; x < vlSize; x++) {
- ((char *)&longValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
- }
-
- jobj =
- ENVPTR->CallStaticObjectMethod(ENVONLY, cLong, longValueMid, longValue);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- }
- break;
- }
- case H5T_FLOAT: {
- switch (vlSize) {
- case sizeof(jfloat): {
- jfloat floatValue;
- for (x = 0; x < vlSize; x++) {
- ((char *)&floatValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
- }
-
- jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cFloat, floatValueMid,
- (double)floatValue);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- case sizeof(jdouble): {
- jdouble doubleValue;
- for (x = 0; x < vlSize; x++) {
- ((char *)&doubleValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
- }
-
- jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cDouble, doubleValueMid,
- doubleValue);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- }
- break;
- }
- case H5T_REFERENCE: {
- jboolean bb;
- jbyte *barray = NULL;
-
- jsize byteArraySize = (jsize)vlSize;
- if (vlSize != (size_t)byteArraySize)
- H5_JNI_FATAL_ERROR(ENVONLY, "H5AreadVL: overflow of byteArraySize");
-
- if (NULL == (jobj = ENVPTR->NewByteArray(ENVONLY, byteArraySize)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
-
- PIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, &bb,
- "readVL reference: byte array not pinned");
-
- for (x = 0; x < vlSize; x++) {
- barray[x] = ((jbyte *)vl_elem.p)[j * vlSize + x];
- }
- if (barray)
- UNPIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, jobj ? 0 : JNI_ABORT);
- break;
- }
- default:
- H5_UNIMPLEMENTED(ENVONLY, "H5AreadVL: invalid class type");
- break;
- }
-
- // Add it to the list
- ENVPTR->CallBooleanMethod(ENVONLY, jList, addMethod, jobj);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- }
- } /* end for */
-
- if (rawBuf)
- HDfree(rawBuf);
- }
- else {
- if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, (void *)readBuf)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- }
-
-done:
- if (readBuf) {
- if ((status >= 0) && vl_data_class) {
- H5Treclaim(attr_id, sid, H5P_DEFAULT, readBuf);
- if (sid >= 0)
- H5Sclose(sid);
- }
-
- UNPIN_BYTE_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
- }
+ status = Java_hdf_hdf5lib_H5_H5Aread(env, clss, attr_id, mem_type_id, (jbyteArray)buf, JNI_TRUE);
return (jint)status;
} /* end Java_hdf_hdf5lib_H5_H5AreadVL */
@@ -1314,206 +1125,9 @@ done:
JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf)
{
- H5T_class_t type_class;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n;
- htri_t vl_data_class;
- herr_t status = FAIL;
- jboolean writeBufIsCopy;
- jbyteArray writeBuf = NULL;
-
- UNUSED(clss);
-
- if (NULL == buf)
- H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5AwriteVL: write buffer is NULL");
-
- /* Get size of data array */
- if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
- H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AwriteVL: readBuf length < 0");
- }
+ herr_t status = FAIL;
- dims[0] = (hsize_t)n;
- if ((sid = H5Screate_simple(1, dims, NULL)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
-
- if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
-
- if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- if (type_class == H5T_VLEN) {
- size_t typeSize;
- hid_t memb = H5I_INVALID_HID;
- H5T_class_t vlClass;
- size_t vlSize;
- void *rawBuf = NULL;
- jobjectArray jList = NULL;
-
- size_t i, j, x;
-
- if (!(typeSize = H5Tget_size(mem_type_id)))
- H5_LIBRARY_ERROR(ENVONLY);
-
- if (!(memb = H5Tget_super(mem_type_id)))
- H5_LIBRARY_ERROR(ENVONLY);
- if ((vlClass = H5Tget_class((hid_t)memb)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- if (!(vlSize = H5Tget_size(memb)))
- H5_LIBRARY_ERROR(ENVONLY);
-
- if (NULL == (rawBuf = HDcalloc((size_t)n, typeSize)))
- H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5AwriteVL: failed to allocate raw VL write buffer");
-
- /* Cache class types */
- /* jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean"); */
- jclass cByte = ENVPTR->FindClass(ENVONLY, "java/lang/Byte");
- jclass cShort = ENVPTR->FindClass(ENVONLY, "java/lang/Short");
- jclass cInt = ENVPTR->FindClass(ENVONLY, "java/lang/Integer");
- jclass cLong = ENVPTR->FindClass(ENVONLY, "java/lang/Long");
- jclass cFloat = ENVPTR->FindClass(ENVONLY, "java/lang/Float");
- jclass cDouble = ENVPTR->FindClass(ENVONLY, "java/lang/Double");
-
- /* jmethodID boolValueMid = ENVPTR->GetMethodID(ENVONLY, cBool, "booleanValue", "()Z"); */
- jmethodID byteValueMid = ENVPTR->GetMethodID(ENVONLY, cByte, "byteValue", "()B");
- jmethodID shortValueMid = ENVPTR->GetMethodID(ENVONLY, cShort, "shortValue", "()S");
- jmethodID intValueMid = ENVPTR->GetMethodID(ENVONLY, cInt, "intValue", "()I");
- jmethodID longValueMid = ENVPTR->GetMethodID(ENVONLY, cLong, "longValue", "()J");
- jmethodID floatValueMid = ENVPTR->GetMethodID(ENVONLY, cFloat, "floatValue", "()F");
- jmethodID doubleValueMid = ENVPTR->GetMethodID(ENVONLY, cDouble, "doubleValue", "()D");
-
- /* Convert each list to a vlen element */
- for (i = 0; i < (size_t)n; i++) {
- hvl_t vl_elem;
-
- if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, (jsize)i)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
-
- // retrieve the java.util.List interface class
- jclass cList = ENVPTR->FindClass(ENVONLY, "java/util/List");
-
- // retrieve the toArray method and invoke it
- jmethodID mToArray = ENVPTR->GetMethodID(ENVONLY, cList, "toArray", "()[Ljava/lang/Object;");
- if (mToArray == NULL)
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- jobjectArray array = (jobjectArray)ENVPTR->CallObjectMethod(ENVONLY, jList, mToArray);
- jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, array);
-
- if (jnelmts < 0)
- H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AwriteVL: number of VL elements < 0");
-
- HDmemcpy(&vl_elem, (char *)rawBuf + i * typeSize, sizeof(hvl_t));
- vl_elem.len = (size_t)jnelmts;
-
- if (NULL == (vl_elem.p = HDmalloc((size_t)jnelmts * vlSize)))
- H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5AwriteVL: failed to allocate vlen ptr buffer");
-
- jobject jobj = NULL;
- for (j = 0; j < (size_t)jnelmts; j++) {
- if (NULL == (jobj = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)array, (jsize)j)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
-
- switch (vlClass) {
- /* case H5T_BOOL: {
- jboolean boolValue = ENVPTR->CallBooleanMethod(ENVONLY, jobj, boolValueMid);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&boolValue)[x];
- }
- break;
- } */
- case H5T_INTEGER: {
- switch (vlSize) {
- case sizeof(jbyte): {
- jbyte byteValue = ENVPTR->CallByteMethod(ENVONLY, jobj, byteValueMid);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&byteValue)[x];
- }
- break;
- }
- case sizeof(jshort): {
- jshort shortValue = ENVPTR->CallShortMethod(ENVONLY, jobj, shortValueMid);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&shortValue)[x];
- }
- break;
- }
- case sizeof(jint): {
- jint intValue = ENVPTR->CallIntMethod(ENVONLY, jobj, intValueMid);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&intValue)[x];
- }
- break;
- }
- case sizeof(jlong): {
- jlong longValue = ENVPTR->CallLongMethod(ENVONLY, jobj, longValueMid);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&longValue)[x];
- }
- break;
- }
- }
- break;
- }
- case H5T_FLOAT: {
- switch (vlSize) {
- case sizeof(jfloat): {
- jfloat floatValue = ENVPTR->CallFloatMethod(ENVONLY, jobj, floatValueMid);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&floatValue)[x];
- }
- break;
- }
- case sizeof(jdouble): {
- jdouble doubleValue = ENVPTR->CallDoubleMethod(ENVONLY, jobj, doubleValueMid);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&doubleValue)[x];
- }
- break;
- }
- }
- break;
- }
- case H5T_REFERENCE: {
- jbyte *barray = (jbyte *)ENVPTR->GetByteArrayElements(ENVONLY, jobj, 0);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)barray)[x];
- }
- ENVPTR->ReleaseByteArrayElements(ENVONLY, jobj, barray, 0);
- break;
- }
- default:
- H5_UNIMPLEMENTED(ENVONLY, "H5AwriteVL: invalid class type");
- break;
- }
- ENVPTR->DeleteLocalRef(ENVONLY, jobj);
- }
-
- HDmemcpy((char *)rawBuf + i * typeSize, &vl_elem, sizeof(hvl_t));
-
- ENVPTR->DeleteLocalRef(ENVONLY, jList);
- } /* end for (i = 0; i < n; i++) */
-
- if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, rawBuf)) < 0)
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
-
- if (rawBuf)
- HDfree(rawBuf);
- }
- else {
- PIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5AwriteVL: write buffer not pinned");
- if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, writeBuf)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- }
-
-done:
- if (writeBuf) {
- if ((status >= 0) && vl_data_class)
- H5Treclaim(attr_id, sid, H5P_DEFAULT, writeBuf);
-
- if (type_class != H5T_VLEN)
- UNPIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
- }
+ status = Java_hdf_hdf5lib_H5_H5Awrite(env, clss, attr_id, mem_type_id, (jbyteArray)buf, JNI_TRUE);
return (jint)status;
} /* end Java_hdf_hdf5lib_H5_H5AwriteVL */
diff --git a/java/src/jni/h5dImp.c b/java/src/jni/h5dImp.c
index 59775e3..0f97522 100644
--- a/java/src/jni/h5dImp.c
+++ b/java/src/jni/h5dImp.c
@@ -182,47 +182,71 @@ Java_hdf_hdf5lib_H5_H5Dread(JNIEnv *env, jclass clss, jlong dataset_id, jlong me
jlong file_space_id, jlong xfer_plist_id, jbyteArray buf,
jboolean isCriticalPinning)
{
- jboolean readBufIsCopy;
- jbyte *readBuf = NULL;
- htri_t vl_data_class;
- herr_t status = FAIL;
+ jboolean readBufIsCopy;
+ jbyte *readBuf = NULL;
+ size_t typeSize;
+ H5T_class_t type_class;
+ jsize vl_array_len; // Only used by vl_data_class types
+ htri_t vl_data_class;
+ herr_t status = FAIL;
UNUSED(clss);
if (NULL == buf)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread: read buffer is NULL");
- /* Get size of data array */
- if (ENVPTR->GetArrayLength(ENVONLY, buf) < 0) {
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
- H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: readBuf length < 0");
- }
-
if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
- if (isCriticalPinning) {
- PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy,
- "H5Dread: read buffer not critically pinned");
+ if (vl_data_class) {
+ /* Get size of data array */
+ if ((vl_array_len = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: readBuf length < 0");
+ }
+
+ if (!(typeSize = H5Tget_size(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ if (NULL == (readBuf = HDcalloc((size_t)vl_array_len, typeSize)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5Dread: failed to allocate raw VL read buffer");
}
else {
- PIN_BYTE_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread: read buffer not pinned");
+ if (isCriticalPinning) {
+ PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy,
+ "H5Dread: read buffer not critically pinned");
+ }
+ else {
+ PIN_BYTE_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread: read buffer not pinned");
+ }
}
if ((status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, (hid_t)file_space_id,
- (hid_t)xfer_plist_id, readBuf)) < 0)
+ (hid_t)xfer_plist_id, (void *)readBuf)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
+ if (vl_data_class) {
+ if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ translate_rbuf(env, buf, mem_type_id, type_class, vl_array_len, readBuf);
+ }
+
done:
if (readBuf) {
if ((status >= 0) && vl_data_class)
H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf);
- if (isCriticalPinning) {
- UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
+ if (vl_data_class) {
+ HDfree(readBuf);
}
else {
- UNPIN_BYTE_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
+ if (isCriticalPinning) {
+ UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
+ }
+ else {
+ UNPIN_BYTE_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
+ }
}
}
@@ -239,31 +263,50 @@ Java_hdf_hdf5lib_H5_H5Dwrite(JNIEnv *env, jclass clss, jlong dataset_id, jlong m
jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jbyteArray buf,
jboolean isCriticalPinning)
{
- jboolean writeBufIsCopy;
- jbyte *writeBuf = NULL;
- htri_t vl_data_class;
- herr_t status = FAIL;
+ jboolean writeBufIsCopy;
+ jbyte *writeBuf = NULL;
+ size_t typeSize;
+ H5T_class_t type_class;
+ jsize vl_array_len; // Only used by vl_data_class types
+ htri_t vl_data_class;
+ herr_t status = FAIL;
UNUSED(clss);
if (NULL == buf)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite: write buffer is NULL");
- /* Get size of data array */
- if (ENVPTR->GetArrayLength(ENVONLY, buf) < 0) {
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
- H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: readBuf length < 0");
- }
-
if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
- if (isCriticalPinning) {
- PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy,
- "H5Dwrite: write buffer not critically pinned");
+ if (vl_data_class) {
+ /* Get size of data array */
+ if ((vl_array_len = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite: write buffer length < 0");
+ }
+
+ if (!(typeSize = H5Tget_size(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ if (NULL == (writeBuf = HDcalloc((size_t)vl_array_len, typeSize)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5Dwrite: failed to allocate raw VL write buffer");
}
else {
- PIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite: write buffer not pinned");
+ if (isCriticalPinning) {
+ PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy,
+ "H5Dwrite: write buffer not critically pinned");
+ }
+ else {
+ PIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite: write buffer not pinned");
+ }
+ }
+
+ if (vl_data_class) {
+ if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ translate_wbuf(ENVONLY, buf, mem_type_id, type_class, vl_array_len, writeBuf);
}
if ((status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, (hid_t)file_space_id,
@@ -275,11 +318,16 @@ done:
if ((status >= 0) && vl_data_class)
H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf);
- if (isCriticalPinning) {
- UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
+ if (vl_data_class) {
+ HDfree(writeBuf);
}
else {
- UNPIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
+ if (isCriticalPinning) {
+ UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
+ }
+ else {
+ UNPIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
+ }
}
}
@@ -1087,235 +1135,10 @@ JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id,
jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jobjectArray buf)
{
- H5T_class_t type_class;
- jsize n;
- htri_t vl_data_class;
- herr_t status = FAIL;
- jbyteArray *readBuf = NULL;
-
- UNUSED(clss);
-
- if (NULL == buf)
- H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5DreadVL: read buffer is NULL");
-
- /* Get size of data array */
- if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
- H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DreadVL: readBuf length < 0");
- }
-
- if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
-
- if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- if (type_class == H5T_VLEN) {
- size_t typeSize;
- hid_t memb = H5I_INVALID_HID;
- H5T_class_t vlClass;
- size_t vlSize;
- void *rawBuf = NULL;
- jobjectArray jList = NULL;
-
- size_t i, j, x;
-
- if (!(typeSize = H5Tget_size(mem_type_id)))
- H5_LIBRARY_ERROR(ENVONLY);
-
- if (!(memb = H5Tget_super(mem_type_id)))
- H5_LIBRARY_ERROR(ENVONLY);
- if ((vlClass = H5Tget_class((hid_t)memb)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- if (!(vlSize = H5Tget_size(memb)))
- H5_LIBRARY_ERROR(ENVONLY);
-
- if (NULL == (rawBuf = HDcalloc((size_t)n, typeSize)))
- H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5DreadVL: failed to allocate raw VL read buffer");
-
- if ((status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id,
- (hid_t)file_space_id, (hid_t)xfer_plist_id, (void *)rawBuf)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
-
- /* Cache class types */
- /* jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean"); */
- jclass cByte = ENVPTR->FindClass(ENVONLY, "java/lang/Byte");
- jclass cShort = ENVPTR->FindClass(ENVONLY, "java/lang/Short");
- jclass cInt = ENVPTR->FindClass(ENVONLY, "java/lang/Integer");
- jclass cLong = ENVPTR->FindClass(ENVONLY, "java/lang/Long");
- jclass cFloat = ENVPTR->FindClass(ENVONLY, "java/lang/Float");
- jclass cDouble = ENVPTR->FindClass(ENVONLY, "java/lang/Double");
-
- /*
- jmethodID boolValueMid =
- ENVPTR->GetStaticMethodID(ENVONLY, cBool, "valueOf", "(Z)Ljava/lang/Boolean;");
- */
- jmethodID byteValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cByte, "valueOf", "(B)Ljava/lang/Byte;");
- jmethodID shortValueMid =
- ENVPTR->GetStaticMethodID(ENVONLY, cShort, "valueOf", "(S)Ljava/lang/Short;");
- jmethodID intValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cInt, "valueOf", "(I)Ljava/lang/Integer;");
- jmethodID longValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cLong, "valueOf", "(J)Ljava/lang/Long;");
- jmethodID floatValueMid =
- ENVPTR->GetStaticMethodID(ENVONLY, cFloat, "valueOf", "(F)Ljava/lang/Float;");
- jmethodID doubleValueMid =
- ENVPTR->GetStaticMethodID(ENVONLY, cDouble, "valueOf", "(D)Ljava/lang/Double;");
-
- // retrieve the java.util.List interface class
- jclass cList = ENVPTR->FindClass(ENVONLY, "java/util/List");
- jmethodID addMethod = ENVPTR->GetMethodID(ENVONLY, cList, "add", "(Ljava/lang/Object;)Z");
-
- /* Convert each element to a list */
- for (i = 0; i < (size_t)n; i++) {
- hvl_t vl_elem;
-
- // The list we're going to return:
- if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, (jsize)i)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
-
- /* Get the number of sequence elements */
- HDmemcpy(&vl_elem, (char *)rawBuf + i * typeSize, sizeof(hvl_t));
-
- jsize nelmts = (jsize)vl_elem.len;
- if (vl_elem.len != (size_t)nelmts)
- H5_JNI_FATAL_ERROR(ENVONLY, "H5DreadVL: overflow of number of VL elements");
- if (nelmts < 0)
- H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DreadVL: number of VL elements < 0");
-
- jobject jobj = NULL;
- for (j = 0; j < (size_t)nelmts; j++) {
- switch (vlClass) {
- /*case H5T_BOOL: {
- jboolean boolValue;
- for (x = 0; x < vlSize; x++) {
- ((char *)&boolValue)[x] = ((char *)vl_elem.p)[j*vlSize+x];
- }
-
- jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cBool, boolValueMid, boolValue);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- } */
- case H5T_INTEGER: {
- switch (vlSize) {
- case sizeof(jbyte): {
- jbyte byteValue;
- for (x = 0; x < vlSize; x++) {
- ((char *)&byteValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
- }
-
- jobj =
- ENVPTR->CallStaticObjectMethod(ENVONLY, cByte, byteValueMid, byteValue);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- case sizeof(jshort): {
- jshort shortValue;
- for (x = 0; x < vlSize; x++) {
- ((char *)&shortValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
- }
-
- jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cShort, shortValueMid,
- shortValue);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- case sizeof(jint): {
- jint intValue;
- for (x = 0; x < vlSize; x++) {
- ((char *)&intValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
- }
-
- jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cInt, intValueMid, intValue);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- case sizeof(jlong): {
- jlong longValue;
- for (x = 0; x < vlSize; x++) {
- ((char *)&longValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
- }
-
- jobj =
- ENVPTR->CallStaticObjectMethod(ENVONLY, cLong, longValueMid, longValue);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- }
- break;
- }
- case H5T_FLOAT: {
- switch (vlSize) {
- case sizeof(jfloat): {
- jfloat floatValue;
- for (x = 0; x < vlSize; x++) {
- ((char *)&floatValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
- }
-
- jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cFloat, floatValueMid,
- (double)floatValue);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- case sizeof(jdouble): {
- jdouble doubleValue;
- for (x = 0; x < vlSize; x++) {
- ((char *)&doubleValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
- }
-
- jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cDouble, doubleValueMid,
- doubleValue);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- }
- break;
- }
- case H5T_REFERENCE: {
- jboolean bb;
- jbyte *barray = NULL;
-
- jsize byteArraySize = (jsize)vlSize;
- if (vlSize != (size_t)byteArraySize)
- H5_JNI_FATAL_ERROR(ENVONLY, "H5DreadVL: overflow of byteArraySize");
-
- if (NULL == (jobj = ENVPTR->NewByteArray(ENVONLY, byteArraySize)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
-
- PIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, &bb,
- "readVL reference: byte array not pinned");
-
- for (x = 0; x < vlSize; x++) {
- barray[x] = ((jbyte *)vl_elem.p)[j * vlSize + x];
- }
- if (barray)
- UNPIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, jobj ? 0 : JNI_ABORT);
- break;
- }
- default:
- H5_UNIMPLEMENTED(ENVONLY, "H5DreadVL: invalid class type");
- break;
- }
-
- // Add it to the list
- ENVPTR->CallBooleanMethod(ENVONLY, jList, addMethod, jobj);
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- }
- } /* end for */
-
- if (rawBuf)
- HDfree(rawBuf);
- }
- else {
- if ((status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id,
- (hid_t)file_space_id, (hid_t)xfer_plist_id, (void *)readBuf)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- }
-
-done:
- if (readBuf) {
- if ((status >= 0) && vl_data_class)
- H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf);
+ herr_t status = FAIL;
- UNPIN_BYTE_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
- }
+ status = Java_hdf_hdf5lib_H5_H5Dread(env, clss, dataset_id, mem_type_id, mem_space_id, file_space_id,
+ xfer_plist_id, (jbyteArray)buf, JNI_TRUE);
return (jint)status;
} /* end Java_hdf_hdf5lib_H5_H5DreadVL */
@@ -1329,202 +1152,10 @@ JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id,
jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jobjectArray buf)
{
- H5T_class_t type_class;
- jsize n;
- htri_t vl_data_class;
- herr_t status = FAIL;
- jboolean writeBufIsCopy;
- jbyteArray writeBuf = NULL;
-
- UNUSED(clss);
-
- if (NULL == buf)
- H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5DwriteVL: write buffer is NULL");
-
- /* Get size of data array */
- if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
- H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DwriteVL: readBuf length < 0");
- }
-
- if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
-
- if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- if (type_class == H5T_VLEN) {
- size_t typeSize;
- hid_t memb = H5I_INVALID_HID;
- H5T_class_t vlClass;
- size_t vlSize;
- void *rawBuf = NULL;
- jobjectArray jList = NULL;
-
- size_t i, j, x;
-
- if (!(typeSize = H5Tget_size(mem_type_id)))
- H5_LIBRARY_ERROR(ENVONLY);
-
- if (!(memb = H5Tget_super(mem_type_id)))
- H5_LIBRARY_ERROR(ENVONLY);
- if ((vlClass = H5Tget_class((hid_t)memb)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- if (!(vlSize = H5Tget_size(memb)))
- H5_LIBRARY_ERROR(ENVONLY);
-
- if (NULL == (rawBuf = HDcalloc((size_t)n, typeSize)))
- H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5DwriteVL: failed to allocate raw VL write buffer");
-
- /* Cache class types */
- /* jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean"); */
- jclass cByte = ENVPTR->FindClass(ENVONLY, "java/lang/Byte");
- jclass cShort = ENVPTR->FindClass(ENVONLY, "java/lang/Short");
- jclass cInt = ENVPTR->FindClass(ENVONLY, "java/lang/Integer");
- jclass cLong = ENVPTR->FindClass(ENVONLY, "java/lang/Long");
- jclass cFloat = ENVPTR->FindClass(ENVONLY, "java/lang/Float");
- jclass cDouble = ENVPTR->FindClass(ENVONLY, "java/lang/Double");
-
- /* jmethodID boolValueMid = ENVPTR->GetMethodID(ENVONLY, cBool, "booleanValue", "()Z"); */
- jmethodID byteValueMid = ENVPTR->GetMethodID(ENVONLY, cByte, "byteValue", "()B");
- jmethodID shortValueMid = ENVPTR->GetMethodID(ENVONLY, cShort, "shortValue", "()S");
- jmethodID intValueMid = ENVPTR->GetMethodID(ENVONLY, cInt, "intValue", "()I");
- jmethodID longValueMid = ENVPTR->GetMethodID(ENVONLY, cLong, "longValue", "()J");
- jmethodID floatValueMid = ENVPTR->GetMethodID(ENVONLY, cFloat, "floatValue", "()F");
- jmethodID doubleValueMid = ENVPTR->GetMethodID(ENVONLY, cDouble, "doubleValue", "()D");
-
- /* Convert each list to a vlen element */
- for (i = 0; i < (size_t)n; i++) {
- hvl_t vl_elem;
-
- if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, (jsize)i)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
-
- // retrieve the java.util.List interface class
- jclass cList = ENVPTR->FindClass(ENVONLY, "java/util/List");
-
- // retrieve the toArray method and invoke it
- jmethodID mToArray = ENVPTR->GetMethodID(ENVONLY, cList, "toArray", "()[Ljava/lang/Object;");
- if (mToArray == NULL)
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- jobjectArray array = (jobjectArray)ENVPTR->CallObjectMethod(ENVONLY, jList, mToArray);
- jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, array);
-
- if (jnelmts < 0)
- H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DwriteVL: number of VL elements < 0");
-
- HDmemcpy(&vl_elem, (char *)rawBuf + i * typeSize, sizeof(hvl_t));
- vl_elem.len = (size_t)jnelmts;
-
- if (NULL == (vl_elem.p = HDmalloc((size_t)jnelmts * vlSize)))
- H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5DwriteVL: failed to allocate vlen ptr buffer");
-
- jobject jobj = NULL;
- for (j = 0; j < (size_t)jnelmts; j++) {
- if (NULL == (jobj = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)array, (jsize)j)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
-
- switch (vlClass) {
- /* case H5T_BOOL: {
- jboolean boolValue = ENVPTR->CallBooleanMethod(ENVONLY, jobj, boolValueMid);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&boolValue)[x];
- }
- break;
- } */
- case H5T_INTEGER: {
- switch (vlSize) {
- case sizeof(jbyte): {
- jbyte byteValue = ENVPTR->CallByteMethod(ENVONLY, jobj, byteValueMid);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&byteValue)[x];
- }
- break;
- }
- case sizeof(jshort): {
- jshort shortValue = ENVPTR->CallShortMethod(ENVONLY, jobj, shortValueMid);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&shortValue)[x];
- }
- break;
- }
- case sizeof(jint): {
- jint intValue = ENVPTR->CallIntMethod(ENVONLY, jobj, intValueMid);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&intValue)[x];
- }
- break;
- }
- case sizeof(jlong): {
- jlong longValue = ENVPTR->CallLongMethod(ENVONLY, jobj, longValueMid);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&longValue)[x];
- }
- break;
- }
- }
- break;
- }
- case H5T_FLOAT: {
- switch (vlSize) {
- case sizeof(jfloat): {
- jfloat floatValue = ENVPTR->CallFloatMethod(ENVONLY, jobj, floatValueMid);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&floatValue)[x];
- }
- break;
- }
- case sizeof(jdouble): {
- jdouble doubleValue = ENVPTR->CallDoubleMethod(ENVONLY, jobj, doubleValueMid);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&doubleValue)[x];
- }
- break;
- }
- }
- break;
- }
- case H5T_REFERENCE: {
- jbyte *barray = (jbyte *)ENVPTR->GetByteArrayElements(ENVONLY, jobj, 0);
- for (x = 0; x < vlSize; x++) {
- ((char *)vl_elem.p)[j * vlSize + x] = ((char *)barray)[x];
- }
- ENVPTR->ReleaseByteArrayElements(ENVONLY, jobj, barray, 0);
- break;
- }
- default:
- H5_UNIMPLEMENTED(ENVONLY, "H5DwriteVL: invalid class type");
- break;
- }
- ENVPTR->DeleteLocalRef(ENVONLY, jobj);
- }
-
- HDmemcpy((char *)rawBuf + i * typeSize, &vl_elem, sizeof(hvl_t));
-
- ENVPTR->DeleteLocalRef(ENVONLY, jList);
- } /* end for (i = 0; i < n; i++) */
-
- if ((status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id,
- (hid_t)file_space_id, (hid_t)xfer_plist_id, rawBuf)) < 0)
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
-
- if (rawBuf)
- HDfree(rawBuf);
- }
- else {
- PIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5DwriteVL: write buffer not pinned");
- if ((status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id,
- (hid_t)file_space_id, (hid_t)xfer_plist_id, writeBuf)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- }
-
-done:
- if (writeBuf) {
- if ((status >= 0) && vl_data_class)
- H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf);
+ herr_t status = FAIL;
- if (type_class != H5T_VLEN)
- UNPIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
- }
+ status = Java_hdf_hdf5lib_H5_H5Dwrite(env, clss, dataset_id, mem_type_id, mem_space_id, file_space_id,
+ xfer_plist_id, (jbyteArray)buf, JNI_TRUE);
return (jint)status;
} /* end Java_hdf_hdf5lib_H5_H5DwriteVL */
diff --git a/java/src/jni/h5fImp.c b/java/src/jni/h5fImp.c
index 2d2b0f2..5ff1db1 100644
--- a/java/src/jni/h5fImp.c
+++ b/java/src/jni/h5fImp.c
@@ -742,7 +742,7 @@ Java_hdf_hdf5lib_H5_H5Fset_1dset_1no_1attrs_1hint(JNIEnv *env, jclass clss, jlon
done:
return;
-}
+} /* end Java_hdf_hdf5lib_H5_H5Fset_1dset_1no_1attrs_1hint */
/*
* Class: hdf_hdf5lib_H5
@@ -765,7 +765,7 @@ Java_hdf_hdf5lib_H5_H5Fget_1dset_1no_1attrs_1hint(JNIEnv *env, jclass clss, jlon
done:
return bval;
-}
+} /* end Java_hdf_hdf5lib_H5_H5Fget_1dset_1no_1attrs_1hint */
/*
* Class: hdf_hdf5lib_H5
diff --git a/java/src/jni/h5tImp.c b/java/src/jni/h5tImp.c
index 5a1d398..c0161f9 100644
--- a/java/src/jni/h5tImp.c
+++ b/java/src/jni/h5tImp.c
@@ -1688,7 +1688,7 @@ Java_hdf_hdf5lib_H5_H5Tflush(JNIEnv *env, jclass clss, jlong loc_id)
done:
return;
-}
+} /* end Java_hdf_hdf5lib_H5_H5Tflush */
/*
* Class: hdf_hdf5lib_H5
@@ -1705,7 +1705,7 @@ Java_hdf_hdf5lib_H5_H5Trefresh(JNIEnv *env, jclass clss, jlong loc_id)
done:
return;
-}
+} /* end Java_hdf_hdf5lib_H5_H5Trefresh */
#ifdef __cplusplus
} /* end extern "C" */
diff --git a/java/src/jni/h5util.c b/java/src/jni/h5util.c
index 37d0194..265213e 100644
--- a/java/src/jni/h5util.c
+++ b/java/src/jni/h5util.c
@@ -4043,6 +4043,551 @@ done:
H5Aclose(attr_id);
} /* end Java_hdf_hdf5lib_H5_H5export_1attribute */
+herr_t
+translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t type_class, jsize count,
+ jbyte *raw_buf)
+{
+ herr_t status = FAIL;
+ hid_t memb = H5I_INVALID_HID;
+ H5T_class_t vlClass;
+ size_t vlSize;
+ jobjectArray jList = NULL;
+ size_t i, j, x;
+
+ /* retrieve the java.util.ArrayList interface class */
+ jclass arrCList = ENVPTR->FindClass(ENVONLY, "java/util/ArrayList");
+ jmethodID arrListMethod = ENVPTR->GetMethodID(ENVONLY, arrCList, "<init>", "(I)V");
+ jmethodID arrAddMethod = ENVPTR->GetMethodID(ENVONLY, arrCList, "add", "(Ljava/lang/Object;)Z");
+
+ /* Cache class types */
+ /* jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean"); */
+ jclass cByte = ENVPTR->FindClass(ENVONLY, "java/lang/Byte");
+ jclass cShort = ENVPTR->FindClass(ENVONLY, "java/lang/Short");
+ jclass cInt = ENVPTR->FindClass(ENVONLY, "java/lang/Integer");
+ jclass cLong = ENVPTR->FindClass(ENVONLY, "java/lang/Long");
+ jclass cFloat = ENVPTR->FindClass(ENVONLY, "java/lang/Float");
+ jclass cDouble = ENVPTR->FindClass(ENVONLY, "java/lang/Double");
+ /*jobjectArray
+ jmethodID boolValueMid =
+ ENVPTR->GetStaticMethodID(ENVONLY, cBool, "valueOf", "(Z)Ljava/lang/Boolean;");
+ */
+ jmethodID byteValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cByte, "valueOf", "(B)Ljava/lang/Byte;");
+ jmethodID shortValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cShort, "valueOf", "(S)Ljava/lang/Short;");
+ jmethodID intValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cInt, "valueOf", "(I)Ljava/lang/Integer;");
+ jmethodID longValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cLong, "valueOf", "(J)Ljava/lang/Long;");
+ jmethodID floatValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cFloat, "valueOf", "(F)Ljava/lang/Float;");
+ jmethodID doubleValueMid =
+ ENVPTR->GetStaticMethodID(ENVONLY, cDouble, "valueOf", "(D)Ljava/lang/Double;");
+
+ if (type_class == H5T_VLEN) {
+ if (!(memb = H5Tget_super(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((vlClass = H5Tget_class(memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ /* Convert each element to a list */
+ for (i = 0; i < (size_t)count; i++) {
+ hvl_t vl_elem;
+ jboolean found_jList = JNI_TRUE;
+
+ /* Get the number of sequence elements */
+ HDmemcpy(&vl_elem, (char *)raw_buf + i * sizeof(hvl_t), sizeof(hvl_t));
+ jsize nelmts = (jsize)vl_elem.len;
+ if (vl_elem.len != (size_t)nelmts)
+ H5_JNI_FATAL_ERROR(ENVONLY, "translate_rbuf: overflow of number of VL elements");
+
+ if (nelmts < 0)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "translate_rbuf: number of VL elements < 0");
+
+ /* The list we're going to return: */
+ if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)ret_buf, (jsize)i))) {
+ found_jList = JNI_FALSE;
+ if (NULL == (jList = (jobjectArray)ENVPTR->NewObject(ENVONLY, arrCList, arrListMethod, 0)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_rbuf: failed to allocate list read buffer");
+ }
+
+ if ((vlClass == H5T_ARRAY) || (vlClass == H5T_COMPOUND) || (vlClass == H5T_VLEN))
+ translate_rbuf(ENVONLY, jList, memb, vlClass, (jsize)nelmts, vl_elem.p);
+ else {
+ jobject jobj = NULL;
+ for (j = 0; j < (size_t)nelmts; j++) {
+ switch (vlClass) {
+ /*case H5T_BOOL: {
+ jboolean boolValue;
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&boolValue)[x] = ((char *)vl_elem.p)[j*vlSize+x];
+ }
+
+ jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cBool, boolValueMid, boolValue);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ } */
+ case H5T_INTEGER: {
+ switch (vlSize) {
+ case sizeof(jbyte): {
+ jbyte byteValue;
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&byteValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
+ }
+ jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cByte, byteValueMid,
+ byteValue);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ case sizeof(jshort): {
+ jshort shortValue;
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&shortValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
+ }
+ jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cShort, shortValueMid,
+ shortValue);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ case sizeof(jint): {
+ jint intValue;
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&intValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
+ }
+ jobj =
+ ENVPTR->CallStaticObjectMethod(ENVONLY, cInt, intValueMid, intValue);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ break;
+ }
+ case sizeof(jlong): {
+ jlong longValue;
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&longValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
+ }
+ jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cLong, longValueMid,
+ longValue);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ }
+ break;
+ }
+ case H5T_FLOAT: {
+ switch (vlSize) {
+ case sizeof(jfloat): {
+ jfloat floatValue;
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&floatValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
+ }
+ jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cFloat, floatValueMid,
+ (double)floatValue);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ case sizeof(jdouble): {
+ jdouble doubleValue;
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&doubleValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
+ }
+ jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cDouble, doubleValueMid,
+ doubleValue);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ }
+ break;
+ }
+ case H5T_REFERENCE: {
+ jboolean bb;
+ jbyte *barray = NULL;
+ jsize byteArraySize = (jsize)vlSize;
+
+ if (vlSize != (size_t)byteArraySize)
+ H5_JNI_FATAL_ERROR(ENVONLY, "translate_rbuf: overflow of byteArraySize");
+
+ if (NULL == (jobj = ENVPTR->NewByteArray(ENVONLY, byteArraySize)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+ PIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, &bb,
+ "read(translate_buf) reference: byte array not pinned");
+ for (x = 0; x < vlSize; x++) {
+ barray[x] = ((jbyte *)vl_elem.p)[j * vlSize + x];
+ }
+ if (barray)
+ UNPIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, jobj ? 0 : JNI_ABORT);
+
+ break;
+ }
+ default:
+ H5_UNIMPLEMENTED(ENVONLY, "translate_rbuf: invalid class type");
+ break;
+ }
+ /* Add it to the list */
+ if (jobj) {
+ ENVPTR->CallBooleanMethod(ENVONLY, jList, arrAddMethod, jobj);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+
+ ENVPTR->DeleteLocalRef(ENVONLY, jobj);
+ }
+ }
+ if (!found_jList) {
+ ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jList);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ ENVPTR->DeleteLocalRef(ENVONLY, jList);
+ }
+ }
+ }
+ }
+ else if (type_class == H5T_COMPOUND) {
+ int nmembs = H5Tget_nmembers(mem_type_id);
+ void *objBuf = NULL;
+ size_t offset;
+
+ if (nmembs < 0)
+ goto done;
+
+ /* Convert each element to a list */
+ for (i = 0; i < (size_t)nmembs; i++) {
+ jboolean found_jList = JNI_TRUE;
+
+ if ((memb = H5Tget_member_type(mem_type_id, (unsigned int)i)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ offset = H5Tget_member_offset(mem_type_id, (unsigned int)i);
+
+ if ((vlClass = H5Tget_class(memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ /* Get the object element */
+ HDmemcpy(&objBuf, (char *)raw_buf + offset, vlSize);
+
+ /* The list we're going to return: */
+ if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)ret_buf, (jsize)i))) {
+ found_jList = JNI_FALSE;
+ if (NULL == (jList = (jobjectArray)ENVPTR->NewObject(ENVONLY, arrCList, arrListMethod, 0)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_rbuf: failed to allocate list read buffer");
+ }
+
+ if ((vlClass == H5T_ARRAY) || (vlClass == H5T_COMPOUND) || (vlClass == H5T_VLEN))
+ translate_rbuf(ENVONLY, jList, memb, vlClass, (jsize)1, objBuf);
+ else {
+ jobject jobj = NULL;
+ switch (vlClass) {
+ /*case H5T_BOOL: {
+ jboolean boolValue;
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&boolValue)[x] = ((char *)vl_elem.p)[j*vlSize+x];
+ }
+
+ jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cBool, boolValueMid, boolValue);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ } */
+ case H5T_INTEGER: {
+ switch (vlSize) {
+ case sizeof(jbyte): {
+ jbyte byteValue;
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&byteValue)[x] = ((char *)objBuf)[vlSize + x];
+ }
+
+ jobj =
+ ENVPTR->CallStaticObjectMethod(ENVONLY, cByte, byteValueMid, byteValue);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ case sizeof(jshort): {
+ jshort shortValue;
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&shortValue)[x] = ((char *)objBuf)[vlSize + x];
+ }
+
+ jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cShort, shortValueMid,
+ shortValue);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ case sizeof(jint): {
+ jint intValue;
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&intValue)[x] = ((char *)objBuf)[vlSize + x];
+ }
+
+ jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cInt, intValueMid, intValue);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ case sizeof(jlong): {
+ jlong longValue;
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&longValue)[x] = ((char *)objBuf)[vlSize + x];
+ }
+
+ jobj =
+ ENVPTR->CallStaticObjectMethod(ENVONLY, cLong, longValueMid, longValue);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ }
+ break;
+ }
+ case H5T_FLOAT: {
+ switch (vlSize) {
+ case sizeof(jfloat): {
+ jfloat floatValue;
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&floatValue)[x] = ((char *)objBuf)[vlSize + x];
+ }
+
+ jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cFloat, floatValueMid,
+ (double)floatValue);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ case sizeof(jdouble): {
+ jdouble doubleValue;
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&doubleValue)[x] = ((char *)objBuf)[vlSize + x];
+ }
+
+ jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cDouble, doubleValueMid,
+ doubleValue);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ }
+ break;
+ }
+ case H5T_REFERENCE: {
+ jboolean bb;
+ jbyte *barray = NULL;
+
+ jsize byteArraySize = (jsize)vlSize;
+ if (vlSize != (size_t)byteArraySize)
+ H5_JNI_FATAL_ERROR(ENVONLY, "translate_rbuf: overflow of byteArraySize");
+
+ if (NULL == (jobj = ENVPTR->NewByteArray(ENVONLY, byteArraySize)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+ PIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, &bb,
+ "translate_rbuf reference: byte array not pinned");
+
+ for (x = 0; x < vlSize; x++) {
+ barray[x] = ((jbyte *)objBuf)[vlSize + x];
+ }
+ if (barray)
+ UNPIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, jobj ? 0 : JNI_ABORT);
+ break;
+ }
+ default:
+ H5_UNIMPLEMENTED(ENVONLY, "translate_rbuf: invalid class type");
+ break;
+ }
+ /* Add it to the list */
+ if (jobj) {
+ ENVPTR->CallBooleanMethod(ENVONLY, jList, arrAddMethod, jobj);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+
+ ENVPTR->DeleteLocalRef(ENVONLY, jobj);
+ }
+ }
+ if (!found_jList) {
+ ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jList);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ ENVPTR->DeleteLocalRef(ENVONLY, jList);
+ }
+ }
+ H5Tclose(memb);
+ }
+ else if (type_class == H5T_ARRAY) {
+ if (!(memb = H5Tget_super(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((vlClass = H5Tget_class(memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ // TODO
+ H5_UNIMPLEMENTED(ENVONLY, "translate_rbuf: invalid H5T_ARRAY type");
+ }
+
+done:
+
+ return (jint)status;
+}
+
+herr_t
+translate_wbuf(JNIEnv *env, jobjectArray in_buf, jlong mem_type_id, H5T_class_t type_class, jsize count,
+ jbyte *raw_buf)
+{
+ herr_t status = FAIL;
+ hid_t memb = H5I_INVALID_HID;
+ H5T_class_t vlClass;
+ size_t vlSize;
+ jobjectArray jList = NULL;
+ size_t i, j, x;
+
+ /* retrieve the java.util.ArrayList interface class */
+ jclass arrCList = ENVPTR->FindClass(ENVONLY, "java/util/ArrayList");
+ /* retrieve the toArray method */
+ jmethodID mToArray = ENVPTR->GetMethodID(ENVONLY, arrCList, "toArray", "()[Ljava/lang/Object;");
+
+ /* Cache class types */
+ /* jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean"); */
+ jclass cByte = ENVPTR->FindClass(ENVONLY, "java/lang/Byte");
+ jclass cShort = ENVPTR->FindClass(ENVONLY, "java/lang/Short");
+ jclass cInt = ENVPTR->FindClass(ENVONLY, "java/lang/Integer");
+ jclass cLong = ENVPTR->FindClass(ENVONLY, "java/lang/Long");
+ jclass cFloat = ENVPTR->FindClass(ENVONLY, "java/lang/Float");
+ jclass cDouble = ENVPTR->FindClass(ENVONLY, "java/lang/Double");
+
+ /* jmethodID boolValueMid = ENVPTR->GetMethodID(ENVONLY, cBool, "booleanValue", "()Z"); */
+ jmethodID byteValueMid = ENVPTR->GetMethodID(ENVONLY, cByte, "byteValue", "()B");
+ jmethodID shortValueMid = ENVPTR->GetMethodID(ENVONLY, cShort, "shortValue", "()S");
+ jmethodID intValueMid = ENVPTR->GetMethodID(ENVONLY, cInt, "intValue", "()I");
+ jmethodID longValueMid = ENVPTR->GetMethodID(ENVONLY, cLong, "longValue", "()J");
+ jmethodID floatValueMid = ENVPTR->GetMethodID(ENVONLY, cFloat, "floatValue", "()F");
+ jmethodID doubleValueMid = ENVPTR->GetMethodID(ENVONLY, cDouble, "doubleValue", "()D");
+
+ if (type_class == H5T_VLEN) {
+ if (!(memb = H5Tget_super(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((vlClass = H5Tget_class((hid_t)memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ /* Convert each list to a vlen element */
+ for (i = 0; i < (size_t)count; i++) {
+ hvl_t vl_elem;
+
+ if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)in_buf, (jsize)i)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+ /* invoke the toArray method */
+ if (mToArray == NULL)
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ jobjectArray array = (jobjectArray)ENVPTR->CallObjectMethod(ENVONLY, jList, mToArray);
+ jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, array);
+
+ if (jnelmts < 0)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "translate_wbuf: number of VL elements < 0");
+
+ vl_elem.len = (size_t)jnelmts;
+
+ if (NULL == (vl_elem.p = HDmalloc((size_t)jnelmts * vlSize)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_wbuf: failed to allocate vlen ptr buffer");
+
+ if ((vlClass == H5T_ARRAY) || (vlClass == H5T_COMPOUND) || (vlClass == H5T_VLEN))
+ translate_wbuf(ENVONLY, (jobjectArray)array, memb, vlClass, (jsize)jnelmts, vl_elem.p);
+ else {
+ jobject jobj = NULL;
+ for (j = 0; j < (size_t)jnelmts; j++) {
+ if (NULL ==
+ (jobj = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)array, (jsize)j)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+ switch (vlClass) {
+ /* case H5T_BOOL: {
+ jboolean boolValue = ENVPTR->CallBooleanMethod(ENVONLY, jobj, boolValueMid);
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&boolValue)[x];
+ }
+ break;
+ } */
+ case H5T_INTEGER: {
+ switch (vlSize) {
+ case sizeof(jbyte): {
+ jbyte byteValue = ENVPTR->CallByteMethod(ENVONLY, jobj, byteValueMid);
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&byteValue)[x];
+ }
+ break;
+ }
+ case sizeof(jshort): {
+ jshort shortValue = ENVPTR->CallShortMethod(ENVONLY, jobj, shortValueMid);
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&shortValue)[x];
+ }
+ break;
+ }
+ case sizeof(jint): {
+ jint intValue = ENVPTR->CallIntMethod(ENVONLY, jobj, intValueMid);
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&intValue)[x];
+ }
+ break;
+ }
+ case sizeof(jlong): {
+ jlong longValue = ENVPTR->CallLongMethod(ENVONLY, jobj, longValueMid);
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&longValue)[x];
+ }
+ break;
+ }
+ }
+ break;
+ }
+ case H5T_FLOAT: {
+ switch (vlSize) {
+ case sizeof(jfloat): {
+ jfloat floatValue = ENVPTR->CallFloatMethod(ENVONLY, jobj, floatValueMid);
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&floatValue)[x];
+ }
+ break;
+ }
+ case sizeof(jdouble): {
+ jdouble doubleValue =
+ ENVPTR->CallDoubleMethod(ENVONLY, jobj, doubleValueMid);
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&doubleValue)[x];
+ }
+ break;
+ }
+ }
+ break;
+ }
+ case H5T_REFERENCE: {
+ jbyte *barray = (jbyte *)ENVPTR->GetByteArrayElements(ENVONLY, jobj, 0);
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)barray)[x];
+ }
+ ENVPTR->ReleaseByteArrayElements(ENVONLY, jobj, barray, 0);
+ break;
+ }
+ default:
+ H5_UNIMPLEMENTED(ENVONLY, "translate_wbuf: invalid class type");
+ break;
+ }
+ ENVPTR->DeleteLocalRef(ENVONLY, jobj);
+ }
+ }
+
+ HDmemcpy((char *)raw_buf + i * sizeof(hvl_t), &vl_elem, sizeof(hvl_t));
+
+ ENVPTR->DeleteLocalRef(ENVONLY, jList);
+ } /* end for (i = 0; i < count; i++) */
+ }
+ else if (type_class == H5T_COMPOUND) {
+ // TODO
+ H5_UNIMPLEMENTED(ENVONLY, "translate_wbuf: invalid H5T_COMPOUND type");
+ }
+ else if (type_class == H5T_ARRAY) {
+ if (!(memb = H5Tget_super(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((vlClass = H5Tget_class(memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ // TODO
+ H5_UNIMPLEMENTED(ENVONLY, "translate_wbuf: invalid H5T_ARRAY type");
+ }
+
+done:
+
+ return (jint)status;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/java/src/jni/h5util.h b/java/src/jni/h5util.h
index 24c1116..5b9da13 100644
--- a/java/src/jni/h5util.h
+++ b/java/src/jni/h5util.h
@@ -52,6 +52,11 @@ extern int h5str_dump_simple_mem(JNIEnv *env, FILE *stream, hid_t attr, int b
extern htri_t H5Tdetect_variable_str(hid_t tid);
+extern herr_t translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t type_class,
+ jsize count, jbyte *raw_buf);
+extern herr_t translate_wbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t type_class,
+ jsize count, jbyte *raw_buf);
+
/*
* Symbols used to format the output of h5str_sprintf and
* to interpret the input to h5str_convert.
diff --git a/java/test/TestH5A.java b/java/test/TestH5A.java
index 4437ec7..095691e 100644
--- a/java/test/TestH5A.java
+++ b/java/test/TestH5A.java
@@ -1415,7 +1415,7 @@ public class TestH5A {
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
assertTrue("testH5AVLwr: ", attr_int_id >= 0);
- H5.H5AwriteVL(attr_int_id, atype_int_id, vl_int_data);
+ H5.H5Awrite(attr_int_id, atype_int_id, vl_int_data);
}
catch (Exception err) {
if (attr_int_id > 0)
@@ -1472,7 +1472,7 @@ public class TestH5A {
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
assertTrue("testH5AVLwr: ", attr_dbl_id >= 0);
- H5.H5AwriteVL(attr_dbl_id, atype_dbl_id, vl_dbl_data);
+ H5.H5Awrite(attr_dbl_id, atype_dbl_id, vl_dbl_data);
}
catch (Exception err) {
if (attr_dbl_id > 0)
@@ -1511,7 +1511,7 @@ public class TestH5A {
vl_readbuf[j] = new ArrayList<Integer>();
try {
- H5.H5AreadVL(attr_int_id, atype_int_id, vl_readbuf);
+ H5.H5Aread(attr_int_id, atype_int_id, vl_readbuf);
}
catch (Exception ex) {
ex.printStackTrace();
@@ -1531,7 +1531,7 @@ public class TestH5A {
vl_readbuf[j] = new ArrayList<Double>();
try {
- H5.H5AreadVL(attr_dbl_id, atype_dbl_id, vl_readbuf);
+ H5.H5Aread(attr_dbl_id, atype_dbl_id, vl_readbuf);
}
catch (Exception ex) {
ex.printStackTrace();
@@ -1576,4 +1576,157 @@ public class TestH5A {
}
}
}
+
+ @Test
+ public void testH5AVLwrVL()
+ {
+ String attr_int_name = "VLIntdata";
+ long attr_int_id = HDF5Constants.H5I_INVALID_HID;
+ long atype_int_id = HDF5Constants.H5I_INVALID_HID;
+ long base_atype_int_id = HDF5Constants.H5I_INVALID_HID;
+ long aspace_id = HDF5Constants.H5I_INVALID_HID;
+ long[] dims = {4};
+ long lsize = 1;
+
+ ArrayList[] base_vl_int_data = new ArrayList[4];
+ ArrayList[] vl_int_data = new ArrayList[4];
+ try {
+ // Write Integer data
+ vl_int_data[0] = new ArrayList<Integer>(Arrays.asList(1));
+ vl_int_data[1] = new ArrayList<Integer>(Arrays.asList(2, 3));
+ vl_int_data[2] = new ArrayList<Integer>(Arrays.asList(4, 5, 6));
+ vl_int_data[3] = new ArrayList<Integer>(Arrays.asList(7, 8, 9, 10));
+ Class dataClass = vl_int_data.getClass();
+ assertTrue("testH5AVLwrVL.getClass: " + dataClass, dataClass.isArray());
+
+ // Write VL data
+ base_vl_int_data[0] = new ArrayList<ArrayList<Integer>>();
+ base_vl_int_data[0].add(vl_int_data[0]);
+ base_vl_int_data[1] = new ArrayList<ArrayList<Integer>>();
+ base_vl_int_data[1].add(vl_int_data[0]);
+ base_vl_int_data[1].add(vl_int_data[1]);
+ base_vl_int_data[2] = new ArrayList<ArrayList<Integer>>();
+ base_vl_int_data[2].add(vl_int_data[0]);
+ base_vl_int_data[2].add(vl_int_data[1]);
+ base_vl_int_data[2].add(vl_int_data[2]);
+ base_vl_int_data[3] = new ArrayList<ArrayList<Integer>>();
+ base_vl_int_data[3].add(vl_int_data[0]);
+ base_vl_int_data[3].add(vl_int_data[1]);
+ base_vl_int_data[3].add(vl_int_data[2]);
+ base_vl_int_data[3].add(vl_int_data[3]);
+
+ try {
+ atype_int_id = H5.H5Tvlen_create(HDF5Constants.H5T_STD_U32LE);
+ assertTrue("testH5AVLwr.H5Tvlen_create: ", atype_int_id >= 0);
+ base_atype_int_id = H5.H5Tvlen_create(atype_int_id);
+ assertTrue("testH5AVLwrVL.H5Tvlen_create: ", base_atype_int_id >= 0);
+ }
+ catch (Exception err) {
+ if (base_atype_int_id > 0)
+ try {
+ H5.H5Tclose(base_atype_int_id);
+ }
+ catch (Exception ex) {
+ }
+ err.printStackTrace();
+ fail("H5.testH5AVLwrVL: " + err);
+ }
+
+ try {
+ aspace_id = H5.H5Screate_simple(1, dims, null);
+ assertTrue(aspace_id > 0);
+ attr_int_id = H5.H5Acreate(H5did, attr_int_name, base_atype_int_id, aspace_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5AVLwrVL: ", attr_int_id >= 0);
+
+ H5.H5Awrite(attr_int_id, base_atype_int_id, base_vl_int_data);
+ }
+ catch (Exception err) {
+ if (attr_int_id > 0)
+ try {
+ H5.H5Aclose(attr_int_id);
+ }
+ catch (Exception ex) {
+ }
+ if (atype_int_id > 0)
+ try {
+ H5.H5Tclose(atype_int_id);
+ }
+ catch (Exception ex) {
+ }
+ err.printStackTrace();
+ fail("H5.testH5AVLwrVL: " + err);
+ }
+ finally {
+ if (aspace_id > 0)
+ try {
+ H5.H5Sclose(aspace_id);
+ }
+ catch (Exception ex) {
+ }
+ }
+
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+
+ for (int j = 0; j < dims.length; j++)
+ lsize *= dims[j];
+
+ // Read Integer data
+ ArrayList[] base_vl_readbuf = new ArrayList[4];
+ for (int j = 0; j < lsize; j++)
+ base_vl_readbuf[j] = new ArrayList<ArrayList<Integer>>();
+
+ try {
+ H5.H5Aread(attr_int_id, base_atype_int_id, base_vl_readbuf);
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ ArrayList vl_readbuf = (ArrayList)base_vl_readbuf[0];
+ assertTrue("vl_readbuf exists", vl_readbuf != null);
+ assertTrue("vl_readbuf has size " + vl_readbuf.size(), vl_readbuf.size() > 0);
+ ArrayList vl_readbuf_int = (ArrayList)vl_readbuf.get(0);
+ assertTrue("testH5AVLwrVL:" + vl_readbuf_int.get(0),
+ vl_int_data[0].get(0).equals(vl_readbuf_int.get(0)));
+
+ vl_readbuf = (ArrayList)base_vl_readbuf[1];
+ vl_readbuf_int = (ArrayList)vl_readbuf.get(1);
+ assertTrue("testH5AVLwrVL:" + vl_readbuf_int.get(0),
+ vl_int_data[1].get(0).equals(vl_readbuf_int.get(0)));
+
+ vl_readbuf = (ArrayList)base_vl_readbuf[2];
+ vl_readbuf_int = (ArrayList)vl_readbuf.get(2);
+ assertTrue("testH5AVLwrVL:" + vl_readbuf_int.get(0),
+ vl_int_data[2].get(0).equals(vl_readbuf_int.get(0)));
+
+ vl_readbuf = (ArrayList)base_vl_readbuf[3];
+ vl_readbuf_int = (ArrayList)vl_readbuf.get(3);
+ assertTrue("testH5AVLwrVL:" + vl_readbuf_int.get(0),
+ vl_int_data[3].get(0).equals(vl_readbuf_int.get(0)));
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.testH5AVLwrVL: " + err);
+ }
+ finally {
+ if (attr_int_id > 0)
+ try {
+ H5.H5Aclose(attr_int_id);
+ }
+ catch (Exception ex) {
+ }
+ if (atype_int_id > 0)
+ try {
+ H5.H5Tclose(atype_int_id);
+ }
+ catch (Exception ex) {
+ }
+ if (base_atype_int_id > 0)
+ try {
+ H5.H5Tclose(base_atype_int_id);
+ }
+ catch (Exception ex) {
+ }
+ }
+ }
}
diff --git a/java/test/TestH5D.java b/java/test/TestH5D.java
index f7e5702..ec9caa3 100644
--- a/java/test/TestH5D.java
+++ b/java/test/TestH5D.java
@@ -1064,8 +1064,8 @@ public class TestH5D {
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
assertTrue("testH5DVLwr: ", dset_int_id >= 0);
- H5.H5DwriteVL(dset_int_id, dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, vl_int_data);
+ H5.H5Dwrite(dset_int_id, dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, vl_int_data);
}
catch (Exception err) {
if (dset_int_id > 0)
@@ -1123,8 +1123,8 @@ public class TestH5D {
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
assertTrue("testH5DVLwr: ", dset_dbl_id >= 0);
- H5.H5DwriteVL(dset_dbl_id, dtype_dbl_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, vl_dbl_data);
+ H5.H5Dwrite(dset_dbl_id, dtype_dbl_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, vl_dbl_data);
}
catch (Exception err) {
if (dset_dbl_id > 0)
@@ -1153,9 +1153,8 @@ public class TestH5D {
H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
- for (int j = 0; j < dims.length; j++) {
+ for (int j = 0; j < dims.length; j++)
lsize *= dims[j];
- }
// Read Integer data
ArrayList[] vl_readbuf = new ArrayList[4];
@@ -1163,8 +1162,8 @@ public class TestH5D {
vl_readbuf[j] = new ArrayList<Integer>();
try {
- H5.H5DreadVL(dset_int_id, dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, vl_readbuf);
+ H5.H5Dread(dset_int_id, dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, vl_readbuf);
}
catch (Exception ex) {
ex.printStackTrace();
@@ -1184,8 +1183,8 @@ public class TestH5D {
vl_readbuf[j] = new ArrayList<Double>();
try {
- H5.H5DreadVL(dset_dbl_id, dtype_dbl_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, vl_readbuf);
+ H5.H5Dread(dset_dbl_id, dtype_dbl_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, vl_readbuf);
}
catch (Exception ex) {
ex.printStackTrace();
@@ -1230,4 +1229,166 @@ public class TestH5D {
}
}
}
+
+ @Test
+ public void testH5DVLwrVL()
+ {
+ String dset_int_name = "VLIntdata";
+ long dset_int_id = HDF5Constants.H5I_INVALID_HID;
+ long dtype_int_id = HDF5Constants.H5I_INVALID_HID;
+ long base_dtype_int_id = HDF5Constants.H5I_INVALID_HID;
+ long dspace_id = HDF5Constants.H5I_INVALID_HID;
+ long[] dims = {4};
+ long lsize = 1;
+
+ ArrayList[] base_vl_int_data = new ArrayList[4];
+ ArrayList[] vl_int_data = new ArrayList[4];
+ try {
+ // Write Integer data
+ vl_int_data[0] = new ArrayList<Integer>(Arrays.asList(1));
+ vl_int_data[1] = new ArrayList<Integer>(Arrays.asList(2, 3));
+ vl_int_data[2] = new ArrayList<Integer>(Arrays.asList(4, 5, 6));
+ vl_int_data[3] = new ArrayList<Integer>(Arrays.asList(7, 8, 9, 10));
+ Class dataClass = vl_int_data.getClass();
+ assertTrue("testH5DVLwrVL.getClass: " + dataClass, dataClass.isArray());
+
+ // Write VL data
+ base_vl_int_data[0] = new ArrayList<ArrayList<Integer>>();
+ base_vl_int_data[0].add(vl_int_data[0]);
+ base_vl_int_data[1] = new ArrayList<ArrayList<Integer>>();
+ base_vl_int_data[1].add(vl_int_data[0]);
+ base_vl_int_data[1].add(vl_int_data[1]);
+ base_vl_int_data[2] = new ArrayList<ArrayList<Integer>>();
+ base_vl_int_data[2].add(vl_int_data[0]);
+ base_vl_int_data[2].add(vl_int_data[1]);
+ base_vl_int_data[2].add(vl_int_data[2]);
+ base_vl_int_data[3] = new ArrayList<ArrayList<Integer>>();
+ base_vl_int_data[3].add(vl_int_data[0]);
+ base_vl_int_data[3].add(vl_int_data[1]);
+ base_vl_int_data[3].add(vl_int_data[2]);
+ base_vl_int_data[3].add(vl_int_data[3]);
+
+ try {
+ dtype_int_id = H5.H5Tvlen_create(HDF5Constants.H5T_STD_U32LE);
+ assertTrue("testH5DVLwrVL.H5Tvlen_create: ", dtype_int_id >= 0);
+ base_dtype_int_id = H5.H5Tvlen_create(dtype_int_id);
+ assertTrue("testH5DVLwrVL.H5Tvlen_create: ", base_dtype_int_id >= 0);
+ }
+ catch (Exception err) {
+ if (base_dtype_int_id > 0)
+ try {
+ H5.H5Tclose(base_dtype_int_id);
+ }
+ catch (Exception ex) {
+ }
+ if (dtype_int_id > 0)
+ try {
+ H5.H5Tclose(dtype_int_id);
+ }
+ catch (Exception ex) {
+ }
+ err.printStackTrace();
+ fail("H5.testH5DVLwrVL: " + err);
+ }
+
+ try {
+ dspace_id = H5.H5Screate_simple(1, dims, null);
+ assertTrue(dspace_id > 0);
+ dset_int_id = H5.H5Dcreate(H5fid, dset_int_name, base_dtype_int_id, dspace_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5DVLwrVL: ", dset_int_id >= 0);
+
+ H5.H5Dwrite(dset_int_id, base_dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, base_vl_int_data);
+ }
+ catch (Exception err) {
+ if (dset_int_id > 0)
+ try {
+ H5.H5Dclose(dset_int_id);
+ }
+ catch (Exception ex) {
+ }
+ if (dtype_int_id > 0)
+ try {
+ H5.H5Tclose(dtype_int_id);
+ }
+ catch (Exception ex) {
+ }
+ err.printStackTrace();
+ fail("H5.testH5DVLwrVL: " + err);
+ }
+ finally {
+ if (dspace_id > 0)
+ try {
+ H5.H5Sclose(dspace_id);
+ }
+ catch (Exception ex) {
+ }
+ }
+
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+
+ for (int j = 0; j < dims.length; j++)
+ lsize *= dims[j];
+
+ // Read Integer data
+ ArrayList[] base_vl_readbuf = new ArrayList[4];
+ for (int j = 0; j < lsize; j++)
+ base_vl_readbuf[j] = new ArrayList<ArrayList<Integer>>();
+
+ try {
+ H5.H5Dread(dset_int_id, base_dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, base_vl_readbuf);
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ ArrayList vl_readbuf = (ArrayList)base_vl_readbuf[0];
+ assertTrue("vl_readbuf exists", vl_readbuf != null);
+ assertTrue("vl_readbuf has size " + vl_readbuf.size(), vl_readbuf.size() > 0);
+ ArrayList vl_readbuf_int = (ArrayList)vl_readbuf.get(0);
+ assertTrue("testH5DVLwrVL:" + vl_readbuf_int.get(0),
+ vl_int_data[0].get(0).equals(vl_readbuf_int.get(0)));
+
+ vl_readbuf = (ArrayList)base_vl_readbuf[1];
+ vl_readbuf_int = (ArrayList)vl_readbuf.get(1);
+ assertTrue("testH5DVLwrVL:" + vl_readbuf_int.get(0),
+ vl_int_data[1].get(0).equals(vl_readbuf_int.get(0)));
+
+ vl_readbuf = (ArrayList)base_vl_readbuf[2];
+ vl_readbuf_int = (ArrayList)vl_readbuf.get(2);
+ assertTrue("testH5DVLwrVL:" + vl_readbuf_int.get(0),
+ vl_int_data[2].get(0).equals(vl_readbuf_int.get(0)));
+
+ vl_readbuf = (ArrayList)base_vl_readbuf[3];
+ vl_readbuf_int = (ArrayList)vl_readbuf.get(3);
+ assertTrue("testH5DVLwrVL:" + vl_readbuf_int.get(0),
+ vl_int_data[3].get(0).equals(vl_readbuf_int.get(0)));
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.testH5DVLwrVL: " + err);
+ }
+ finally {
+ if (dset_int_id > 0)
+ try {
+ H5.H5Dclose(dset_int_id);
+ }
+ catch (Exception ex) {
+ }
+ if (dtype_int_id > 0)
+ try {
+ H5.H5Tclose(dtype_int_id);
+ }
+ catch (Exception ex) {
+ }
+ if (base_dtype_int_id > 0)
+ try {
+ H5.H5Tclose(base_dtype_int_id);
+ }
+ catch (Exception ex) {
+ }
+ }
+ }
}
diff --git a/java/test/TestH5R.java b/java/test/TestH5R.java
index 221a71e..1dcf992 100644
--- a/java/test/TestH5R.java
+++ b/java/test/TestH5R.java
@@ -600,7 +600,7 @@ public class TestH5R {
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
assertTrue("testH5RVLattr_ref: ", attr_obj_id >= 0);
- H5.H5AwriteVL(attr_obj_id, atype_obj_id, vl_obj_data);
+ H5.H5Awrite(attr_obj_id, atype_obj_id, vl_obj_data);
}
catch (Exception err) {
if (attr_obj_id > 0)
@@ -657,7 +657,7 @@ public class TestH5R {
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
assertTrue("testH5RVLattr_ref: ", attr_reg_id >= 0);
- H5.H5AwriteVL(attr_reg_id, atype_reg_id, vl_reg_data);
+ H5.H5Awrite(attr_reg_id, atype_reg_id, vl_reg_data);
}
catch (Exception err) {
if (attr_reg_id > 0)
@@ -696,7 +696,7 @@ public class TestH5R {
vl_readbuf[j] = new ArrayList<byte[]>();
try {
- H5.H5AreadVL(attr_obj_id, atype_obj_id, vl_readbuf);
+ H5.H5Aread(attr_obj_id, atype_obj_id, vl_readbuf);
}
catch (Exception ex) {
ex.printStackTrace();
@@ -716,7 +716,7 @@ public class TestH5R {
vl_readbuf[j] = new ArrayList<byte[]>();
try {
- H5.H5AreadVL(attr_reg_id, atype_reg_id, vl_readbuf);
+ H5.H5Aread(attr_reg_id, atype_reg_id, vl_readbuf);
}
catch (Exception ex) {
ex.printStackTrace();
@@ -831,8 +831,8 @@ public class TestH5R {
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
assertTrue("testH5RVLdset_ref: ", dset_obj_id >= 0);
- H5.H5DwriteVL(dset_obj_id, dtype_obj_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, vl_obj_data);
+ H5.H5Dwrite(dset_obj_id, dtype_obj_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, vl_obj_data);
}
catch (Exception err) {
if (dset_obj_id > 0)
@@ -890,8 +890,8 @@ public class TestH5R {
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
assertTrue("testH5RVLdset_ref: ", dset_reg_id >= 0);
- H5.H5DwriteVL(dset_reg_id, dtype_reg_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, vl_reg_data);
+ H5.H5Dwrite(dset_reg_id, dtype_reg_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, vl_reg_data);
}
catch (Exception err) {
if (dset_reg_id > 0)
@@ -930,8 +930,8 @@ public class TestH5R {
vl_readbuf[j] = new ArrayList<byte[]>();
try {
- H5.H5DreadVL(dset_obj_id, dtype_obj_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, vl_readbuf);
+ H5.H5Dread(dset_obj_id, dtype_obj_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, vl_readbuf);
}
catch (Exception ex) {
ex.printStackTrace();
@@ -951,8 +951,8 @@ public class TestH5R {
vl_readbuf[j] = new ArrayList<byte[]>();
try {
- H5.H5DreadVL(dset_reg_id, dtype_reg_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, vl_readbuf);
+ H5.H5Dread(dset_reg_id, dtype_reg_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, vl_readbuf);
}
catch (Exception ex) {
ex.printStackTrace();
diff --git a/java/test/testfiles/JUnit-TestH5A.txt b/java/test/testfiles/JUnit-TestH5A.txt
index efdd4a2..edd493c 100644
--- a/java/test/testfiles/JUnit-TestH5A.txt
+++ b/java/test/testfiles/JUnit-TestH5A.txt
@@ -11,6 +11,7 @@ JUnit version 4.11
.testH5Aget_info_by_name
.testH5Aget_create_plist
.testH5Adelete_by_name
+.testH5AVLwrVL
.testH5Aopen_by_name
.testH5Aget_info
.testH5Aget_name
@@ -31,5 +32,5 @@ JUnit version 4.11
Time: XXXX
-OK (29 tests)
+OK (30 tests)
diff --git a/java/test/testfiles/JUnit-TestH5D.txt b/java/test/testfiles/JUnit-TestH5D.txt
index 288e6d0..cdeaed3 100644
--- a/java/test/testfiles/JUnit-TestH5D.txt
+++ b/java/test/testfiles/JUnit-TestH5D.txt
@@ -1,4 +1,5 @@
JUnit version 4.11
+.testH5DVLwrVL
.testH5Dget_storage_size
.testH5Diterate_write
.testH5Dcreate
@@ -22,5 +23,5 @@ JUnit version 4.11
Time: XXXX
-OK (20 tests)
+OK (21 tests)