From 02a5508e50073cd533a150ac923b028d1d7af013 Mon Sep 17 00:00:00 2001 From: Allen Byrne <50328838+byrnHDF@users.noreply.github.com> Date: Thu, 28 Apr 2022 22:46:21 -0500 Subject: Reinstate java API removed in 1.10.8 (#1697) * Revert java API removal with JNI private function * Fix name typo * Correct format --- CMakeLists.txt | 3 ++ java/src/hdf/hdf5lib/H5.java | 37 ++++++++++++++++++++---- java/src/jni/h5util.c | 68 ++++++++++++++++++++++++++++++++++++++++++++ java/src/jni/h5util.h | 8 ++++++ 4 files changed, 111 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 71ab918..f5c9876 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,10 +2,13 @@ cmake_minimum_required (VERSION 3.12) project (HDF5 C) if (POLICY CMP0074) + # find_package() uses _ROOT variables. cmake_policy (SET CMP0074 NEW) endif () if (POLICY CMP0083) + # To control generation of Position Independent Executable (PIE) or not, + # some flags are required at link time. cmake_policy (SET CMP0083 NEW) endif () diff --git a/java/src/hdf/hdf5lib/H5.java b/java/src/hdf/hdf5lib/H5.java index 443fb25..c2af7b6 100644 --- a/java/src/hdf/hdf5lib/H5.java +++ b/java/src/hdf/hdf5lib/H5.java @@ -534,6 +534,33 @@ public class H5 implements java.io.Serializable { throws HDF5LibraryException; /** + * H5export_dataset is a utility function to save data in a file. + * + * @param file_export_name + * The file name to export data into. + * @param file_name + * The name of the HDF5 file containing the dataset. + * @param object_path + * The full path of the dataset to be exported. + * @param binary_order + * 99 - export data as text. + * 1 - export data as binary Native Order. + * 2 - export data as binary Little Endian. + * 3 - export data as binary Big Endian. + * + * @exception HDF5LibraryException + * Error from the HDF-5 Library. + **/ + public static void H5export_dataset(String file_export_name, String file_name, String object_path, + int binary_order) throws HDF5LibraryException + { + _H5export_dataset_string(file_export_name, file_name, object_path, binary_order); + } + private synchronized static native void _H5export_dataset_string(String file_export_name, String file_name, + String object_path, int binary_order) + throws HDF5LibraryException; + + /** * H5export_attribute is a utility function to save data in a file. * * @param file_export_name @@ -5303,7 +5330,7 @@ public class H5 implements java.io.Serializable { String n[] = new String[1]; n[0] = new String(""); oname[0] = H5Lget_name_by_idx(loc_id, name, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, - idx, HDF5Constants.H5P_DEFAULT); + idx, HDF5Constants.H5P_DEFAULT); H5L_info_t info = H5Lget_info_by_idx(loc_id, name, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, idx, HDF5Constants.H5P_DEFAULT); type[0] = info.type; @@ -11790,8 +11817,8 @@ public class H5 implements java.io.Serializable { * @exception HDF5LibraryException * Error from the HDF-5 Library. **/ - public synchronized static native long H5Sselect_project_intersection(long src_space_id, long dst_space_id, - long src_intersect_space_id) + public synchronized static native long + H5Sselect_project_intersection(long src_space_id, long dst_space_id, long src_intersect_space_id) throws HDF5LibraryException; // //////////////////////////////////////////////////////////// @@ -12633,8 +12660,8 @@ public class H5 implements java.io.Serializable { /** * If any internal bits of a floating point type are unused (that is, those significant bits which are not - * part of the sign, exponent, or mantissa), then H5Tset_inpad will be filled according to the value of the - * padding value property inpad. + * part of the sign, exponent, or mantissa), then H5Tset_inpad will be filled according to the value of + * the padding value property inpad. * * @param type_id * IN: Identifier of datatype to modify. diff --git a/java/src/jni/h5util.c b/java/src/jni/h5util.c index b684d05..4568880 100644 --- a/java/src/jni/h5util.c +++ b/java/src/jni/h5util.c @@ -3512,6 +3512,74 @@ done: /* * Class: hdf_hdf5lib_H5 + * Method: _H5export_dataset_string + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5__1H5export_1dataset_1string(JNIEnv *env, jclass clss, jstring file_export_name, + jstring file_name, jstring object_path, jint binary_order) +{ + const char *file_export = NULL; + const char *fileName = NULL; + const char *object_name = NULL; + jboolean isCopy; + herr_t ret_val = FAIL; + hid_t file_id = H5I_INVALID_HID; + hid_t dataset_id = H5I_INVALID_HID; + FILE * stream = NULL; + + UNUSED(clss); + + if (NULL == file_export_name) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5export_dataset: file_export_name is NULL"); + + if (NULL == file_name) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5export_dataset: file_name is NULL"); + + if (NULL == object_path) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5export_dataset: object_path is NULL"); + + PIN_JAVA_STRING(ENVONLY, file_name, fileName, NULL, "H5export_dataset: file name not pinned"); + + if ((file_id = H5Fopen(fileName, (unsigned)H5F_ACC_RDWR, (hid_t)H5P_DEFAULT)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + PIN_JAVA_STRING(ENVONLY, object_path, object_name, &isCopy, "H5export_dataset: object_path not pinned"); + + if ((dataset_id = H5Dopen2(file_id, object_name, H5P_DEFAULT)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + PIN_JAVA_STRING(ENVONLY, file_export_name, file_export, NULL, + "H5export_dataset: file_export name not pinned"); + + if (NULL == (stream = HDfopen(file_export, "w+"))) + H5_JNI_FATAL_ERROR(ENVONLY, "HDfopen failed"); + + if ((ret_val = h5str_dump_simple_dset(ENVONLY, stream, dataset_id, binary_order)) < 0) + H5_ASSERTION_ERROR(ENVONLY, "h5str_dump_simple_dset failed"); + + if (stream) { + HDfclose(stream); + stream = NULL; + } + +done: + if (stream) + HDfclose(stream); + if (file_export) + UNPIN_JAVA_STRING(ENVONLY, file_export_name, file_export); + if (object_name) + UNPIN_JAVA_STRING(ENVONLY, object_path, object_name); + if (fileName) + UNPIN_JAVA_STRING(ENVONLY, file_name, fileName); + if (dataset_id >= 0) + H5Dclose(dataset_id); + if (file_id >= 0) + H5Fclose(file_id); +} /* end Java_hdf_hdf5lib_H5_H5export_1dataset */ + +/* + * Class: hdf_hdf5lib_H5 * Method: H5export_attribute * Signature: (Ljava/lang/String;JLjava/lang/String;I)V */ diff --git a/java/src/jni/h5util.h b/java/src/jni/h5util.h index 33f1ea7..b7f12bd 100644 --- a/java/src/jni/h5util.h +++ b/java/src/jni/h5util.h @@ -111,6 +111,14 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5export_1dataset(JNIEnv *, jclass, j /* * Class: hdf_hdf5lib_H5 + * Method: _H5export_dataset_string + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V + */ +JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5__1H5export_1dataset_1string(JNIEnv *, jclass, jstring, jstring, + jstring, jint); + +/* + * Class: hdf_hdf5lib_H5 * Method: H5export_attribute * Signature: (Ljava/lang/String;JLjava/lang/String;I)V */ -- cgit v0.12