diff options
author | Allen Byrne <50328838+byrnHDF@users.noreply.github.com> | 2022-11-16 04:44:33 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-16 04:44:33 (GMT) |
commit | 719d800499c6c3a1abbb92871069eed53222fdbb (patch) | |
tree | 23d0086b07472a011f24159d8b6d54ec1047e917 /java | |
parent | 03cc2210165cc02fd50c87e6653c4b95b0bd7d83 (diff) | |
download | hdf5-719d800499c6c3a1abbb92871069eed53222fdbb.zip hdf5-719d800499c6c3a1abbb92871069eed53222fdbb.tar.gz hdf5-719d800499c6c3a1abbb92871069eed53222fdbb.tar.bz2 |
Refactor JNI translate functions to a recursive switch on datatype (#2232)
Diffstat (limited to 'java')
-rw-r--r-- | java/src/jni/h5aImp.c | 106 | ||||
-rw-r--r-- | java/src/jni/h5dImp.c | 89 | ||||
-rw-r--r-- | java/src/jni/h5util.c | 819 | ||||
-rw-r--r-- | java/test/TestH5A.java | 188 | ||||
-rw-r--r-- | java/test/TestH5D.java | 195 | ||||
-rw-r--r-- | java/test/testfiles/JUnit-TestH5A.txt | 3 | ||||
-rw-r--r-- | java/test/testfiles/JUnit-TestH5D.txt | 2 |
7 files changed, 914 insertions, 488 deletions
diff --git a/java/src/jni/h5aImp.c b/java/src/jni/h5aImp.c index 132ce43..71caf76 100644 --- a/java/src/jni/h5aImp.c +++ b/java/src/jni/h5aImp.c @@ -175,10 +175,8 @@ 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 ((vl_array_len = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { - CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + if ((vl_array_len = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); - } if (!(typeSize = H5Tget_size(mem_type_id))) H5_LIBRARY_ERROR(ENVONLY); @@ -1109,9 +1107,56 @@ done: JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf) { - 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; + htri_t vl_data_class; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread: read buffer is NULL"); + + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* Get size of data array */ + if ((vl_array_len = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: 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, "H5Aread: failed to allocate raw VL read buffer"); + + if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, (void *)readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + 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); + } - status = Java_hdf_hdf5lib_H5_H5Aread(env, clss, attr_id, mem_type_id, (jbyteArray)buf, JNI_TRUE); + HDfree(readBuf); + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5AreadVL */ @@ -1124,9 +1169,56 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf) { - 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; + htri_t vl_data_class; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite: write buffer is NULL"); + + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* 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"); + } - status = Java_hdf_hdf5lib_H5_H5Awrite(env, clss, attr_id, mem_type_id, (jbyteArray)buf, JNI_TRUE); + 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"); + + 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) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (writeBuf) { + 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); + } + + HDfree(writeBuf); + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5AwriteVL */ diff --git a/java/src/jni/h5dImp.c b/java/src/jni/h5dImp.c index 1a24bf6..56c5cc8 100644 --- a/java/src/jni/h5dImp.c +++ b/java/src/jni/h5dImp.c @@ -1134,10 +1134,47 @@ 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) { - herr_t status = FAIL; + jboolean readBufIsCopy; + jbyte *readBuf = NULL; + size_t typeSize; + H5T_class_t type_class; + jsize vl_array_len; + htri_t vl_data_class; + herr_t status = FAIL; - 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); + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread: read buffer is NULL"); + + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + /* 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"); + + 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); + 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); + HDfree(readBuf); + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5DreadVL */ @@ -1151,10 +1188,50 @@ 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) { - 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"); + + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* 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"); + } - 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); + 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"); + + 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, + (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); + + HDfree(writeBuf); + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5DwriteVL */ diff --git a/java/src/jni/h5util.c b/java/src/jni/h5util.c index 05138fd..4e62085 100644 --- a/java/src/jni/h5util.c +++ b/java/src/jni/h5util.c @@ -3426,10 +3426,8 @@ Java_hdf_hdf5lib_H5_H5AreadComplex(JNIEnv *env, jclass clss, jlong attr_id, jlon size = (((H5Tget_size(mem_type_id)) > (H5Tget_size(p_type))) ? (H5Tget_size(mem_type_id)) : (H5Tget_size(p_type))); - if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) <= 0) { - CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) <= 0) H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AreadComplex: read buffer length <= 0"); - } if (NULL == (readBuf = (char *)HDmalloc((size_t)n * size))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5AreadComplex: failed to allocate read buffer"); @@ -4046,12 +4044,12 @@ 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; + herr_t status = FAIL; + hid_t memb = H5I_INVALID_HID; + H5T_class_t vlClass; + size_t vlSize; + size_t i, x; + size_t typeSize; /* retrieve the java.util.ArrayList interface class */ jclass arrCList = ENVPTR->FindClass(ENVONLY, "java/util/ArrayList"); @@ -4078,335 +4076,297 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t 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); + if (!(typeSize = H5Tget_size(mem_type_id))) + 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"); - } + switch (type_class) { + case 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; + int ret_buflen = -1; + jobjectArray jList = NULL; + + /* 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"); + + ret_buflen = ENVPTR->GetArrayLength(ENVONLY, ret_buf); + /* The list we're going to return: */ + if (i < ret_buflen) { + jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)ret_buf, (jsize)i); + } + if (NULL == jList) { + 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; + int jListlen = ENVPTR->GetArrayLength(ENVONLY, jList); + if (found_jList == JNI_FALSE) { + jboolean addResult = + ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, (jobject)jList); + if (!addResult) + H5_JNI_FATAL_ERROR(ENVONLY, "translate_rbuf: cannot add VL element"); + } + ENVPTR->DeleteLocalRef(ENVONLY, jList); + } + break; + } /* H5T_VLEN */ + case H5T_COMPOUND: { + int nmembs = H5Tget_nmembers(mem_type_id); + void *objBuf = NULL; + size_t offset; - if (vlSize != (size_t)byteArraySize) - H5_JNI_FATAL_ERROR(ENVONLY, "translate_rbuf: overflow of byteArraySize"); + 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); - if (NULL == (jobj = ENVPTR->NewByteArray(ENVONLY, byteArraySize))) - CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + if (nmembs < 0) + goto done; - 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); + /* Convert each element to a list */ + for (i = 0; i < (size_t)nmembs; i++) { + jboolean found_jList = JNI_TRUE; + jobjectArray jList = NULL; + int ret_buflen = -1; - 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); + 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); - ENVPTR->DeleteLocalRef(ENVONLY, jobj); - } + 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); + + ret_buflen = ENVPTR->GetArrayLength(ENVONLY, ret_buf); + /* The list we're going to return: */ + if (i < ret_buflen) { + if (NULL == + (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)ret_buf, (jsize)i))) + found_jList = JNI_FALSE; + } + if (NULL == jList) { + if (NULL == + (jList = (jobjectArray)ENVPTR->NewObject(ENVONLY, arrCList, arrListMethod, 0))) + H5_OUT_OF_MEMORY_ERROR(ENVONLY, + "translate_rbuf: failed to allocate list read buffer"); } + + translate_rbuf(ENVONLY, jList, memb, vlClass, (jsize)1, objBuf); 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; + H5Tclose(memb); + break; + } /* H5T_COMPOUND */ + case H5T_ARRAY: { + void *objBuf = NULL; + size_t typeCount; - if ((memb = H5Tget_member_type(mem_type_id, (unsigned int)i)) < 0) + if (!(memb = H5Tget_super(mem_type_id))) 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); + if (!(typeSize = H5Tget_size(mem_type_id))) + H5_LIBRARY_ERROR(ENVONLY); + + typeCount = typeSize / vlSize; + + if (NULL == (objBuf = HDmalloc(typeSize))) + H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_rbuf: failed to allocate buffer"); + + /* Convert each element to a list */ + for (i = 0; i < (size_t)count; i++) { + jboolean found_jList = JNI_TRUE; + jobjectArray jList = NULL; + int ret_buflen = -1; + + /* Get the object element */ + HDmemcpy((char *)objBuf, (char *)raw_buf + i * typeSize, typeSize); - /* 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"); + ret_buflen = ENVPTR->GetArrayLength(ENVONLY, ret_buf); + /* The list we're going to return: */ + if (i < ret_buflen) { + if (NULL == + (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)ret_buf, (jsize)i))) + found_jList = JNI_FALSE; + } + if (NULL == jList) { + if (NULL == + (jList = (jobjectArray)ENVPTR->NewObject(ENVONLY, arrCList, arrListMethod, 0))) + H5_OUT_OF_MEMORY_ERROR(ENVONLY, + "translate_rbuf: failed to allocate list read buffer"); + } + + translate_rbuf(ENVONLY, jList, memb, vlClass, (jsize)typeCount, objBuf); + if (!found_jList) { + ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jList); + ENVPTR->DeleteLocalRef(ENVONLY, jList); + } } - if ((vlClass == H5T_ARRAY) || (vlClass == H5T_COMPOUND) || (vlClass == H5T_VLEN)) - translate_rbuf(ENVONLY, jList, memb, vlClass, (jsize)1, objBuf); - else { + if (objBuf) + HDfree(objBuf); + + break; + } /* H5T_ARRAY */ + case H5T_INTEGER: { + /* Convert each element to a list */ + for (i = 0; i < (size_t)count; i++) { 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]; + switch (typeSize) { + case sizeof(jbyte): { + jbyte byteValue; + for (x = 0; x < typeSize; x++) { + ((char *)&byteValue)[x] = ((char *)raw_buf)[i * typeSize + x]; } - jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cBool, boolValueMid, boolValue); - CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + if (NULL == + (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cByte, byteValueMid, byteValue))) + 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; - } + } + case sizeof(jshort): { + jshort shortValue; + for (x = 0; x < typeSize; x++) { + ((char *)&shortValue)[x] = ((char *)raw_buf)[i * typeSize + x]; } + + if (NULL == (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cShort, shortValueMid, + shortValue))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); 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; - } + case sizeof(jint): { + jint intValue; + for (x = 0; x < typeSize; x++) { + ((char *)&intValue)[x] = ((char *)raw_buf)[i * typeSize + x]; } + + if (NULL == + (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cInt, intValueMid, intValue))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); 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"); + case sizeof(jlong): { + jlong longValue; + for (x = 0; x < typeSize; x++) { + ((char *)&longValue)[x] = ((char *)raw_buf)[i * typeSize + x]; + } - if (NULL == (jobj = ENVPTR->NewByteArray(ENVONLY, byteArraySize))) + if (NULL == + (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cLong, longValueMid, longValue))) 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]; + break; + } + } + if (jobj) { + ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jobj); + ENVPTR->DeleteLocalRef(ENVONLY, jobj); + } + else { + } + } + break; + } /* H5T_INTEGER */ + case H5T_FLOAT: { + /* Convert each element to a list */ + for (i = 0; i < (size_t)count; i++) { + jobject jobj = NULL; + switch (typeSize) { + case sizeof(jfloat): { + jfloat floatValue; + for (x = 0; x < typeSize; x++) { + ((char *)&floatValue)[x] = ((char *)raw_buf)[i * typeSize + x]; } - if (barray) - UNPIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, jobj ? 0 : JNI_ABORT); + + if (NULL == (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cFloat, floatValueMid, + (double)floatValue))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); break; } - default: - H5_UNIMPLEMENTED(ENVONLY, "translate_rbuf: invalid class type"); + case sizeof(jdouble): { + jdouble doubleValue; + for (x = 0; x < typeSize; x++) { + ((char *)&doubleValue)[x] = ((char *)raw_buf)[i * typeSize + x]; + } + + if (NULL == (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cDouble, doubleValueMid, + doubleValue))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); break; + } } - /* Add it to the list */ if (jobj) { - ENVPTR->CallBooleanMethod(ENVONLY, jList, arrAddMethod, jobj); - CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); - + ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jobj); 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); + break; + } /* H5T_FLOAT */ + case H5T_REFERENCE: { + /* Convert each element to a list */ + for (i = 0; i < (size_t)count; i++) { + jboolean bb; + jbyte *barray = NULL; + jobject jobj = NULL; - // TODO - H5_UNIMPLEMENTED(ENVONLY, "translate_rbuf: invalid H5T_ARRAY type"); - } + jsize byteArraySize = (jsize)typeSize; + if (typeSize != (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 < typeSize; x++) { + barray[x] = ((jbyte *)raw_buf)[i * typeSize + x]; + } + if (barray) + UNPIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, jobj ? 0 : JNI_ABORT); + + if (jobj) { + ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jobj); + ENVPTR->DeleteLocalRef(ENVONLY, jobj); + } + } + break; + } /* H5T_REFERENCE */ + default: + H5_UNIMPLEMENTED(ENVONLY, "translate_rbuf: invalid class type"); + break; + } /* switch(type_class) */ done: @@ -4419,10 +4379,12 @@ translate_wbuf(JNIEnv *env, jobjectArray in_buf, jlong mem_type_id, H5T_class_t { herr_t status = FAIL; hid_t memb = H5I_INVALID_HID; + jobjectArray jList = NULL; + jobject jobj = NULL; H5T_class_t vlClass; size_t vlSize; - jobjectArray jList = NULL; - size_t i, j, x; + size_t i, x; + size_t typeSize; /* retrieve the java.util.ArrayList interface class */ jclass arrCList = ENVPTR->FindClass(ENVONLY, "java/util/ArrayList"); @@ -4446,141 +4408,168 @@ translate_wbuf(JNIEnv *env, jobjectArray in_buf, jlong mem_type_id, H5T_class_t 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); + if (!(typeSize = H5Tget_size(mem_type_id))) + H5_LIBRARY_ERROR(ENVONLY); - /* Convert each list to a vlen element */ - for (i = 0; i < (size_t)count; i++) { - hvl_t vl_elem; + switch (type_class) { + case 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); - if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)in_buf, (jsize)i))) - CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + /* Convert each list to a vlen element */ + for (i = 0; i < (size_t)count; i++) { + hvl_t vl_elem; - /* 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 (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)in_buf, (jsize)i))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - if (jnelmts < 0) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "translate_wbuf: number of VL elements < 0"); + /* 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; + 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 (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; + + HDmemcpy((char *)raw_buf + i * sizeof(hvl_t), &vl_elem, sizeof(hvl_t)); + + ENVPTR->DeleteLocalRef(ENVONLY, jList); + } /* end for (i = 0; i < count; i++) */ + break; + } /* H5T_VLEN */ + case H5T_COMPOUND: { + H5_UNIMPLEMENTED(ENVONLY, "translate_wbuf: invalid H5T_COMPOUND type"); + break; + } /* H5T_COMPOUND */ + case H5T_ARRAY: { + void *objBuf = NULL; + + 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 list to an array element */ + for (i = 0; i < (size_t)count; i++) { + 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 array elements < 0"); + + if (NULL == (objBuf = HDmalloc((size_t)jnelmts * vlSize))) + H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_wbuf: failed to allocate buffer"); + + translate_wbuf(ENVONLY, (jobjectArray)array, memb, vlClass, (jsize)jnelmts, objBuf); + + HDmemcpy((char *)raw_buf + i * vlSize * jnelmts, (char *)objBuf, vlSize * jnelmts); + + ENVPTR->DeleteLocalRef(ENVONLY, jList); + } /* end for (i = 0; i < count; i++) */ + break; + } /* H5T_ARRAY */ + case H5T_INTEGER: { + /* Convert each list to an array element */ + for (i = 0; i < (size_t)count; i++) { + if (NULL == (jobj = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)in_buf, (jsize)i))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + switch (typeSize) { + case sizeof(jbyte): { + jbyte byteValue = ENVPTR->CallByteMethod(ENVONLY, jobj, byteValueMid); + for (x = 0; x < typeSize; x++) { + ((char *)raw_buf)[i * typeSize + x] = ((char *)&byteValue)[x]; } - 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; + break; + } + case sizeof(jshort): { + jshort shortValue = ENVPTR->CallShortMethod(ENVONLY, jobj, shortValueMid); + for (x = 0; x < typeSize; x++) { + ((char *)raw_buf)[i * typeSize + x] = ((char *)&shortValue)[x]; } - 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; + break; + } + case sizeof(jint): { + jint intValue = ENVPTR->CallIntMethod(ENVONLY, jobj, intValueMid); + for (x = 0; x < typeSize; x++) { + ((char *)raw_buf)[i * typeSize + x] = ((char *)&intValue)[x]; } - default: - H5_UNIMPLEMENTED(ENVONLY, "translate_wbuf: invalid class type"); - break; + break; + } + case sizeof(jlong): { + jlong longValue = ENVPTR->CallLongMethod(ENVONLY, jobj, longValueMid); + for (x = 0; x < typeSize; x++) { + ((char *)raw_buf)[i * typeSize + x] = ((char *)&longValue)[x]; + } + break; } - ENVPTR->DeleteLocalRef(ENVONLY, jobj); } + 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"); - } + break; + } /* H5T_INTEGER */ + case H5T_FLOAT: { + /* Convert each list to an array element */ + for (i = 0; i < (size_t)count; i++) { + if (NULL == (jobj = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)in_buf, (jsize)i))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + switch (typeSize) { + case sizeof(jfloat): { + jfloat floatValue = ENVPTR->CallFloatMethod(ENVONLY, jobj, floatValueMid); + for (x = 0; x < typeSize; x++) { + ((char *)raw_buf)[i * typeSize + x] = ((char *)&floatValue)[x]; + } + break; + } + case sizeof(jdouble): { + jdouble doubleValue = ENVPTR->CallDoubleMethod(ENVONLY, jobj, doubleValueMid); + for (x = 0; x < typeSize; x++) { + ((char *)raw_buf)[i * typeSize + x] = ((char *)&doubleValue)[x]; + } + break; + } + } + ENVPTR->DeleteLocalRef(ENVONLY, jobj); + } + break; + } /* H5T_FLOAT */ + case H5T_REFERENCE: { + /* Convert each list to an array element */ + for (i = 0; i < (size_t)count; i++) { + if (NULL == (jobj = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)in_buf, (jsize)i))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + jbyte *barray = (jbyte *)ENVPTR->GetByteArrayElements(ENVONLY, jobj, 0); + for (x = 0; x < typeSize; x++) { + ((char *)raw_buf)[i * typeSize + x] = ((char *)barray)[x]; + } + ENVPTR->ReleaseByteArrayElements(ENVONLY, jobj, barray, 0); + ENVPTR->DeleteLocalRef(ENVONLY, jobj); + } + break; + } + default: + H5_UNIMPLEMENTED(ENVONLY, "translate_wbuf: invalid class type"); + break; + } /* switch(type_class) */ done: diff --git a/java/test/TestH5A.java b/java/test/TestH5A.java index 095691e..d17e16c 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.H5Awrite(attr_int_id, atype_int_id, vl_int_data); + H5.H5AwriteVL(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.H5Awrite(attr_dbl_id, atype_dbl_id, vl_dbl_data); + H5.H5AwriteVL(attr_dbl_id, atype_dbl_id, vl_dbl_data); } catch (Exception err) { if (attr_dbl_id > 0) @@ -1501,9 +1501,8 @@ public class TestH5A { 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]; @@ -1511,7 +1510,7 @@ public class TestH5A { vl_readbuf[j] = new ArrayList<Integer>(); try { - H5.H5Aread(attr_int_id, atype_int_id, vl_readbuf); + H5.H5AreadVL(attr_int_id, atype_int_id, vl_readbuf); } catch (Exception ex) { ex.printStackTrace(); @@ -1531,7 +1530,7 @@ public class TestH5A { vl_readbuf[j] = new ArrayList<Double>(); try { - H5.H5Aread(attr_dbl_id, atype_dbl_id, vl_readbuf); + H5.H5AreadVL(attr_dbl_id, atype_dbl_id, vl_readbuf); } catch (Exception ex) { ex.printStackTrace(); @@ -1628,6 +1627,12 @@ public class TestH5A { } catch (Exception ex) { } + if (atype_int_id > 0) + try { + H5.H5Tclose(atype_int_id); + } + catch (Exception ex) { + } err.printStackTrace(); fail("H5.testH5AVLwrVL: " + err); } @@ -1639,7 +1644,7 @@ public class TestH5A { 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); + H5.H5AwriteVL(attr_int_id, base_atype_int_id, base_vl_int_data); } catch (Exception err) { if (attr_int_id > 0) @@ -1677,32 +1682,47 @@ public class TestH5A { base_vl_readbuf[j] = new ArrayList<ArrayList<Integer>>(); try { - H5.H5Aread(attr_int_id, base_atype_int_id, base_vl_readbuf); + H5.H5AreadVL(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), + ArrayList<ArrayList<Integer>> vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[0]; + assertTrue("vl_readbuf 0 exists", vl_readbuf != null); + ArrayList<Integer> vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(0)); + /* + * System.out.println(); System.out.println("vl_readbuf: " + vl_readbuf); + * System.out.println("vl_readbuf_int: " + vl_readbuf_int); + */ + assertTrue("testHADVLwrVL:" + 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))); + vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[1]; + vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(1)); + /* + * System.out.println("vl_readbuf: " + vl_readbuf); System.out.println("vl_readbuf_int: " + + * vl_readbuf_int); + */ + assertTrue("testH5AVLwrVL:" + vl_readbuf_int.get(1), + vl_int_data[1].get(1).equals(vl_readbuf_int.get(1))); + + vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[2]; + vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(2)); + /* + * System.out.println("vl_readbuf: " + vl_readbuf); System.out.println("vl_readbuf_int: " + + * vl_readbuf_int); + */ + assertTrue("testH5AVLwrVL:" + vl_readbuf_int.get(2), + vl_int_data[2].get(2).equals(vl_readbuf_int.get(2))); + + vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[3]; + vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(3)); + /* + * System.out.println("vl_readbuf: " + vl_readbuf); System.out.println("vl_readbuf_int: " + + * vl_readbuf_int); + */ + assertTrue("testH5AVLwrVL:" + vl_readbuf_int.get(3), + vl_int_data[3].get(3).equals(vl_readbuf_int.get(3))); } catch (Throwable err) { err.printStackTrace(); @@ -1729,4 +1749,118 @@ public class TestH5A { } } } + + @Test + public void testH5AArraywr() + { + String att_int_name = "ArrayIntdata"; + long att_int_id = HDF5Constants.H5I_INVALID_HID; + long atype_int_id = HDF5Constants.H5I_INVALID_HID; + long aspace_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {4}; + long lsize = 1; + + ArrayList[] arr_int_data = new ArrayList[4]; + try { + // Write Integer data + arr_int_data[0] = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4)); + arr_int_data[1] = new ArrayList<Integer>(Arrays.asList(2, 3, 4, 5)); + arr_int_data[2] = new ArrayList<Integer>(Arrays.asList(4, 5, 6, 7)); + arr_int_data[3] = new ArrayList<Integer>(Arrays.asList(7, 8, 9, 10)); + Class dataClass = arr_int_data.getClass(); + assertTrue("testH5AArraywr.getClass: " + dataClass, dataClass.isArray()); + + try { + atype_int_id = H5.H5Tarray_create(HDF5Constants.H5T_STD_U32LE, 1, dims); + assertTrue("testH5AArraywr.H5Tarray_create: ", atype_int_id >= 0); + } + catch (Exception err) { + if (atype_int_id > 0) + try { + H5.H5Tclose(atype_int_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5AArraywr: " + err); + } + + try { + aspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(aspace_id > 0); + att_int_id = H5.H5Acreate(H5did, att_int_name, atype_int_id, aspace_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5AVLwr: ", att_int_id >= 0); + + H5.H5AwriteVL(att_int_id, atype_int_id, arr_int_data); + } + catch (Exception err) { + if (att_int_id > 0) + try { + H5.H5Aclose(att_int_id); + } + catch (Exception ex) { + } + if (atype_int_id > 0) + try { + H5.H5Tclose(atype_int_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5AVLwr: " + 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[] arr_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + arr_readbuf[j] = new ArrayList<Integer>(); + + try { + H5.H5AreadVL(att_int_id, atype_int_id, arr_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + assertTrue("testH5AVLwr:" + arr_readbuf[0].get(0), + arr_int_data[0].get(0).equals(arr_readbuf[0].get(0))); + assertTrue("testH5AVLwr:" + arr_readbuf[1].get(0), + arr_int_data[1].get(0).equals(arr_readbuf[1].get(0))); + assertTrue("testH5AVLwr:" + arr_readbuf[2].get(0), + arr_int_data[2].get(0).equals(arr_readbuf[2].get(0))); + assertTrue("testH5AVLwr:" + arr_readbuf[3].get(0), + arr_int_data[3].get(0).equals(arr_readbuf[3].get(0))); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.testH5AArraywr: " + err); + } + finally { + if (att_int_id > 0) + try { + H5.H5Aclose(att_int_id); + } + catch (Exception ex) { + } + if (atype_int_id > 0) + try { + H5.H5Tclose(atype_int_id); + } + catch (Exception ex) { + } + } + } } diff --git a/java/test/TestH5D.java b/java/test/TestH5D.java index ec9caa3..f204e38 100644 --- a/java/test/TestH5D.java +++ b/java/test/TestH5D.java @@ -31,6 +31,7 @@ import hdf.hdf5lib.exceptions.HDF5LibraryException; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; @@ -964,7 +965,7 @@ public class TestH5D { assertTrue("H5Dvlen_get_buf_size " + vl_size + " == " + str_data_bytes, vl_size == str_data_bytes); } - @Test + @Ignore public void testH5Dvlen_read_default_buffer() throws Throwable { String[] str_data = {"Parting", "is such", "sweet", "sorrow.", "Testing", "one", "two", "three.", @@ -1064,8 +1065,8 @@ public class TestH5D { HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); assertTrue("testH5DVLwr: ", dset_int_id >= 0); - H5.H5Dwrite(dset_int_id, dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, vl_int_data); + H5.H5DwriteVL(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 +1124,8 @@ public class TestH5D { HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); assertTrue("testH5DVLwr: ", dset_dbl_id >= 0); - H5.H5Dwrite(dset_dbl_id, dtype_dbl_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, vl_dbl_data); + H5.H5DwriteVL(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) @@ -1162,8 +1163,8 @@ public class TestH5D { vl_readbuf[j] = new ArrayList<Integer>(); try { - H5.H5Dread(dset_int_id, dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, vl_readbuf); + H5.H5DreadVL(dset_int_id, dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_readbuf); } catch (Exception ex) { ex.printStackTrace(); @@ -1183,8 +1184,8 @@ public class TestH5D { vl_readbuf[j] = new ArrayList<Double>(); try { - H5.H5Dread(dset_dbl_id, dtype_dbl_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, vl_readbuf); + H5.H5DreadVL(dset_dbl_id, dtype_dbl_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_readbuf); } catch (Exception ex) { ex.printStackTrace(); @@ -1299,8 +1300,8 @@ public class TestH5D { 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); + H5.H5DwriteVL(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) @@ -1338,33 +1339,48 @@ public class TestH5D { 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); + H5.H5DreadVL(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); + ArrayList<ArrayList<Integer>> vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[0]; + assertTrue("vl_readbuf 0 exists", vl_readbuf != null); + ArrayList<Integer> vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(0)); + /* + * System.out.println(); System.out.println("vl_readbuf: " + vl_readbuf); + * System.out.println("vl_readbuf_int: " + vl_readbuf_int); + */ 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))); + vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[1]; + vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(1)); + /* + * System.out.println("vl_readbuf: " + vl_readbuf); System.out.println("vl_readbuf_int: " + + * vl_readbuf_int); + */ + assertTrue("testH5DVLwrVL:" + vl_readbuf_int.get(1), + vl_int_data[1].get(1).equals(vl_readbuf_int.get(1))); + + vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[2]; + vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(2)); + /* + * System.out.println("vl_readbuf: " + vl_readbuf); System.out.println("vl_readbuf_int: " + + * vl_readbuf_int); + */ + assertTrue("testH5DVLwrVL:" + vl_readbuf_int.get(2), + vl_int_data[2].get(2).equals(vl_readbuf_int.get(2))); + + vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[3]; + vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(3)); + /* + * System.out.println("vl_readbuf: " + vl_readbuf); System.out.println("vl_readbuf_int: " + + * vl_readbuf_int); + */ + assertTrue("testH5DVLwrVL:" + vl_readbuf_int.get(3), + vl_int_data[3].get(3).equals(vl_readbuf_int.get(3))); } catch (Throwable err) { err.printStackTrace(); @@ -1391,4 +1407,121 @@ public class TestH5D { } } } + + @Test + public void testH5DArraywr() + { + String dset_int_name = "ArrayIntdata"; + long dset_int_id = HDF5Constants.H5I_INVALID_HID; + long dtype_int_id = HDF5Constants.H5I_INVALID_HID; + long dspace_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {4}; + long lsize = 1; + + ArrayList[] arr_int_data = new ArrayList[4]; + try { + // Write Integer data + arr_int_data[0] = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4)); + arr_int_data[1] = new ArrayList<Integer>(Arrays.asList(2, 3, 4, 5)); + arr_int_data[2] = new ArrayList<Integer>(Arrays.asList(4, 5, 6, 7)); + arr_int_data[3] = new ArrayList<Integer>(Arrays.asList(7, 8, 9, 10)); + Class dataClass = arr_int_data.getClass(); + assertTrue("testH5DArraywr.getClass: " + dataClass, dataClass.isArray()); + + try { + dtype_int_id = H5.H5Tarray_create(HDF5Constants.H5T_STD_U32LE, 1, dims); + assertTrue("testH5DArraywr.H5Tarray_create: ", dtype_int_id >= 0); + } + catch (Exception err) { + if (dtype_int_id > 0) + try { + H5.H5Tclose(dtype_int_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5DArraywr: " + err); + } + + try { + dspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(dspace_id > 0); + dset_int_id = + H5.H5Dcreate(H5fid, dset_int_name, dtype_int_id, dspace_id, HDF5Constants.H5P_DEFAULT, + 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, arr_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.testH5DVLwr: " + 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[] arr_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + arr_readbuf[j] = new ArrayList<Integer>(); + + try { + H5.H5DreadVL(dset_int_id, dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, arr_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + assertTrue("testH5DVLwr:" + arr_readbuf[0].get(0), + arr_int_data[0].get(0).equals(arr_readbuf[0].get(0))); + assertTrue("testH5DVLwr:" + arr_readbuf[1].get(0), + arr_int_data[1].get(0).equals(arr_readbuf[1].get(0))); + assertTrue("testH5DVLwr:" + arr_readbuf[2].get(0), + arr_int_data[2].get(0).equals(arr_readbuf[2].get(0))); + assertTrue("testH5DVLwr:" + arr_readbuf[3].get(0), + arr_int_data[3].get(0).equals(arr_readbuf[3].get(0))); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.testH5DArraywr: " + 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) { + } + } + } } diff --git a/java/test/testfiles/JUnit-TestH5A.txt b/java/test/testfiles/JUnit-TestH5A.txt index edd493c..49e5c97 100644 --- a/java/test/testfiles/JUnit-TestH5A.txt +++ b/java/test/testfiles/JUnit-TestH5A.txt @@ -23,6 +23,7 @@ JUnit version 4.11 .testH5Adelete_by_idx_order .testH5Arename_by_name .testH5Acreate2_invalidobject +.testH5AArraywr .testH5Acreate2 .testH5Aiterate_by_name .testH5Adelete_by_idx_null @@ -32,5 +33,5 @@ JUnit version 4.11 Time: XXXX -OK (30 tests) +OK (31 tests) diff --git a/java/test/testfiles/JUnit-TestH5D.txt b/java/test/testfiles/JUnit-TestH5D.txt index cdeaed3..19abd80 100644 --- a/java/test/testfiles/JUnit-TestH5D.txt +++ b/java/test/testfiles/JUnit-TestH5D.txt @@ -1,6 +1,7 @@ JUnit version 4.11 .testH5DVLwrVL .testH5Dget_storage_size +.testH5DArraywr .testH5Diterate_write .testH5Dcreate .testH5Dget_offset @@ -19,7 +20,6 @@ JUnit version 4.11 .testH5Dvlen_write_read .testH5Dget_space .testH5Dget_type_closed -.testH5Dvlen_read_default_buffer Time: XXXX |