summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/examples/datatypes/H5Ex_T_Compound.java94
-rw-r--r--java/examples/datatypes/H5Ex_T_CompoundAttribute.java95
-rw-r--r--java/examples/datatypes/H5Ex_T_VLString.java8
-rw-r--r--java/src/jni/h5aImp.c20
-rw-r--r--java/src/jni/h5dImp.c30
-rw-r--r--java/src/jni/h5util.c901
-rw-r--r--java/src/jni/h5util.h8
-rw-r--r--java/test/TestH5A.java145
-rw-r--r--java/test/TestH5D.java519
-rw-r--r--java/test/testfiles/JUnit-TestH5A.txt3
-rw-r--r--java/test/testfiles/JUnit-TestH5D.txt5
11 files changed, 1407 insertions, 421 deletions
diff --git a/java/examples/datatypes/H5Ex_T_Compound.java b/java/examples/datatypes/H5Ex_T_Compound.java
index a78d0e3..7a46bcf 100644
--- a/java/examples/datatypes/H5Ex_T_Compound.java
+++ b/java/examples/datatypes/H5Ex_T_Compound.java
@@ -23,6 +23,9 @@ package examples.datatypes;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
@@ -87,6 +90,14 @@ public class H5Ex_T_Compound {
this.pressure = pressure;
}
+ Sensor(List data)
+ {
+ this.serial_no = (int)data.get(0);
+ this.location = (String)data.get(1);
+ this.temperature = (double)data.get(2);
+ this.pressure = (double)data.get(3);
+ }
+
Sensor(ByteBuffer databuf, int dbposition) { readBuffer(databuf, dbposition); }
void writeBuffer(ByteBuffer databuf, int dbposition)
@@ -115,6 +126,24 @@ public class H5Ex_T_Compound {
this.pressure = databuf.getDouble(dbposition + Sensor_Datatype.getOffset(3));
}
+ List get()
+ {
+ List data = new ArrayList<>();
+ data.add(this.serial_no);
+ data.add(this.location);
+ data.add(this.temperature);
+ data.add(this.pressure);
+ return data;
+ }
+
+ void put(List data)
+ {
+ this.serial_no = (int)data.get(0);
+ this.location = (String)data.get(1);
+ this.temperature = (double)data.get(2);
+ this.pressure = (double)data.get(3);
+ }
+
@Override
public String toString()
{
@@ -127,21 +156,21 @@ public class H5Ex_T_Compound {
private static void CreateDataset()
{
- long file_id = HDF5Constants.H5I_INVALID_HID;
- long strtype_id = HDF5Constants.H5I_INVALID_HID;
- long memtype_id = HDF5Constants.H5I_INVALID_HID;
- long filetype_id = HDF5Constants.H5I_INVALID_HID;
- long dataspace_id = HDF5Constants.H5I_INVALID_HID;
- long dataset_id = HDF5Constants.H5I_INVALID_HID;
- long[] dims = {DIM0};
- Sensor[] object_data = new Sensor[DIM0];
- byte[] dset_data = null;
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+ long strtype_id = HDF5Constants.H5I_INVALID_HID;
+ long memtype_id = HDF5Constants.H5I_INVALID_HID;
+ long filetype_id = HDF5Constants.H5I_INVALID_HID;
+ long dataspace_id = HDF5Constants.H5I_INVALID_HID;
+ long dataset_id = HDF5Constants.H5I_INVALID_HID;
+ long[] dims = {DIM0};
+ ArrayList[] object_data = new ArrayList[DIM0];
+ byte[] dset_data = null;
// Initialize data.
- object_data[0] = new Sensor(1153, new String("Exterior (static)"), 53.23, 24.57);
- object_data[1] = new Sensor(1184, new String("Intake"), 55.12, 22.95);
- object_data[2] = new Sensor(1027, new String("Intake manifold"), 103.55, 31.23);
- object_data[3] = new Sensor(1313, new String("Exhaust manifold"), 1252.89, 84.11);
+ object_data[0] = (ArrayList) new Sensor(1153, new String("Exterior (static)"), 53.23, 24.57).get();
+ object_data[1] = (ArrayList) new Sensor(1184, new String("Intake"), 55.12, 22.95).get();
+ object_data[2] = (ArrayList) new Sensor(1027, new String("Intake manifold"), 103.55, 31.23).get();
+ object_data[3] = (ArrayList) new Sensor(1313, new String("Exhaust manifold"), 1252.89, 84.11).get();
// Create a new file using default properties.
try {
@@ -220,17 +249,10 @@ public class H5Ex_T_Compound {
}
// Write the compound data to the dataset.
- // allocate memory for read buffer.
- dset_data = new byte[(int)dims[0] * (int)Sensor_Datatype.getDataSize()];
- ByteBuffer outBuf = ByteBuffer.wrap(dset_data);
- outBuf.order(ByteOrder.nativeOrder());
- for (int indx = 0; indx < (int)dims[0]; indx++) {
- object_data[indx].writeBuffer(outBuf, indx * (int)Sensor_Datatype.getDataSize());
- }
try {
if ((dataset_id >= 0) && (memtype_id >= 0))
- H5.H5Dwrite(dataset_id, memtype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, dset_data);
+ H5.H5DwriteVL(dataset_id, memtype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, (Object[])object_data);
}
catch (Exception e) {
e.printStackTrace();
@@ -292,14 +314,13 @@ public class H5Ex_T_Compound {
private static void ReadDataset()
{
- long file_id = HDF5Constants.H5I_INVALID_HID;
- long strtype_id = HDF5Constants.H5I_INVALID_HID;
- long memtype_id = HDF5Constants.H5I_INVALID_HID;
- long dataspace_id = HDF5Constants.H5I_INVALID_HID;
- long dataset_id = HDF5Constants.H5I_INVALID_HID;
- long[] dims = {DIM0};
- Sensor[] object_data2;
- byte[] dset_data;
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+ long strtype_id = HDF5Constants.H5I_INVALID_HID;
+ long memtype_id = HDF5Constants.H5I_INVALID_HID;
+ long dataspace_id = HDF5Constants.H5I_INVALID_HID;
+ long dataset_id = HDF5Constants.H5I_INVALID_HID;
+ long[] dims = {DIM0};
+ Sensor[] object_data2 = new Sensor[(int)dims[0]];
// Open an existing file.
try {
@@ -362,21 +383,16 @@ public class H5Ex_T_Compound {
e.printStackTrace();
}
- // allocate memory for read buffer.
- dset_data = new byte[(int)dims[0] * (int)Sensor_Datatype.getDataSize()];
-
- object_data2 = new Sensor[(int)dims[0]];
+ ArrayList[] object_data = new ArrayList[(int)dims[0]];
// Read data.
try {
if ((dataset_id >= 0) && (memtype_id >= 0))
- H5.H5Dread(dataset_id, memtype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, dset_data);
+ H5.H5DreadVL(dataset_id, memtype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, (Object[])object_data);
- ByteBuffer inBuf = ByteBuffer.wrap(dset_data);
- inBuf.order(ByteOrder.nativeOrder());
for (int indx = 0; indx < (int)dims[0]; indx++) {
- object_data2[indx] = new Sensor(inBuf, indx * (int)Sensor_Datatype.getDataSize());
+ object_data2[indx] = new Sensor(object_data[indx]);
}
}
catch (Exception e) {
diff --git a/java/examples/datatypes/H5Ex_T_CompoundAttribute.java b/java/examples/datatypes/H5Ex_T_CompoundAttribute.java
index f331a1e..93e15fd 100644
--- a/java/examples/datatypes/H5Ex_T_CompoundAttribute.java
+++ b/java/examples/datatypes/H5Ex_T_CompoundAttribute.java
@@ -23,6 +23,9 @@ package examples.datatypes;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
@@ -37,8 +40,6 @@ public class H5Ex_T_CompoundAttribute {
protected static final int DOUBLESIZE = 8;
protected final static int MAXSTRINGSIZE = 80;
- // Using Java Externalization will add a two-byte object header in
- // the stream, which needs to be called out in the datatypes.
static class Sensor_Datatype {
static int numberMembers = 4;
static int[] memberDims = {1, 1, 1, 1};
@@ -90,6 +91,14 @@ public class H5Ex_T_CompoundAttribute {
this.pressure = pressure;
}
+ Sensor(List data)
+ {
+ this.serial_no = (int)data.get(0);
+ this.location = (String)data.get(1);
+ this.temperature = (double)data.get(2);
+ this.pressure = (double)data.get(3);
+ }
+
Sensor(ByteBuffer databuf, int dbposition) { readBuffer(databuf, dbposition); }
void writeBuffer(ByteBuffer databuf, int dbposition)
@@ -118,6 +127,24 @@ public class H5Ex_T_CompoundAttribute {
this.pressure = databuf.getDouble(dbposition + Sensor_Datatype.getOffset(3));
}
+ List get()
+ {
+ List data = new ArrayList<>();
+ data.add(this.serial_no);
+ data.add(this.location);
+ data.add(this.temperature);
+ data.add(this.pressure);
+ return data;
+ }
+
+ void put(List data)
+ {
+ this.serial_no = (int)data.get(0);
+ this.location = (String)data.get(1);
+ this.temperature = (double)data.get(2);
+ this.pressure = (double)data.get(3);
+ }
+
@Override
public String toString()
{
@@ -130,22 +157,22 @@ public class H5Ex_T_CompoundAttribute {
private static void CreateDataset()
{
- long file_id = HDF5Constants.H5I_INVALID_HID;
- long strtype_id = HDF5Constants.H5I_INVALID_HID;
- long memtype_id = HDF5Constants.H5I_INVALID_HID;
- long filetype_id = HDF5Constants.H5I_INVALID_HID;
- long dataspace_id = HDF5Constants.H5I_INVALID_HID;
- long dataset_id = HDF5Constants.H5I_INVALID_HID;
- long attribute_id = HDF5Constants.H5I_INVALID_HID;
- long[] dims = {DIM0};
- Sensor[] object_data = new Sensor[DIM0];
- byte[] dset_data = null;
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+ long strtype_id = HDF5Constants.H5I_INVALID_HID;
+ long memtype_id = HDF5Constants.H5I_INVALID_HID;
+ long filetype_id = HDF5Constants.H5I_INVALID_HID;
+ long dataspace_id = HDF5Constants.H5I_INVALID_HID;
+ long dataset_id = HDF5Constants.H5I_INVALID_HID;
+ long attribute_id = HDF5Constants.H5I_INVALID_HID;
+ long[] dims = {DIM0};
+ ArrayList[] object_data = new ArrayList[DIM0];
+ byte[] dset_data = null;
// Initialize data.
- object_data[0] = new Sensor(1153, new String("Exterior (static)"), 53.23, 24.57);
- object_data[1] = new Sensor(1184, new String("Intake"), 55.12, 22.95);
- object_data[2] = new Sensor(1027, new String("Intake manifold"), 103.55, 31.23);
- object_data[3] = new Sensor(1313, new String("Exhaust manifold"), 1252.89, 84.11);
+ object_data[0] = (ArrayList) new Sensor(1153, new String("Exterior (static)"), 53.23, 24.57).get();
+ object_data[1] = (ArrayList) new Sensor(1184, new String("Intake"), 55.12, 22.95).get();
+ object_data[2] = (ArrayList) new Sensor(1027, new String("Intake manifold"), 103.55, 31.23).get();
+ object_data[3] = (ArrayList) new Sensor(1313, new String("Exhaust manifold"), 1252.89, 84.11).get();
// Create a new file using default properties.
try {
@@ -238,15 +265,9 @@ public class H5Ex_T_CompoundAttribute {
}
// Write the compound data.
- dset_data = new byte[(int)dims[0] * (int)Sensor_Datatype.getDataSize()];
- ByteBuffer outBuf = ByteBuffer.wrap(dset_data);
- outBuf.order(ByteOrder.nativeOrder());
- for (int indx = 0; indx < (int)dims[0]; indx++) {
- object_data[indx].writeBuffer(outBuf, indx * (int)Sensor_Datatype.getDataSize());
- }
try {
if ((attribute_id >= 0) && (memtype_id >= 0))
- H5.H5Awrite(attribute_id, memtype_id, dset_data);
+ H5.H5AwriteVL(attribute_id, memtype_id, (Object[])object_data);
}
catch (Exception e) {
e.printStackTrace();
@@ -316,15 +337,14 @@ public class H5Ex_T_CompoundAttribute {
private static void ReadDataset()
{
- long file_id = HDF5Constants.H5I_INVALID_HID;
- long strtype_id = HDF5Constants.H5I_INVALID_HID;
- long memtype_id = HDF5Constants.H5I_INVALID_HID;
- long dataspace_id = HDF5Constants.H5I_INVALID_HID;
- long dataset_id = HDF5Constants.H5I_INVALID_HID;
- long attribute_id = HDF5Constants.H5I_INVALID_HID;
- long[] dims = {DIM0};
- Sensor[] object_data2;
- byte[] dset_data;
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+ long strtype_id = HDF5Constants.H5I_INVALID_HID;
+ long memtype_id = HDF5Constants.H5I_INVALID_HID;
+ long dataspace_id = HDF5Constants.H5I_INVALID_HID;
+ long dataset_id = HDF5Constants.H5I_INVALID_HID;
+ long attribute_id = HDF5Constants.H5I_INVALID_HID;
+ long[] dims = {DIM0};
+ Sensor[] object_data2 = new Sensor[(int)dims[0]];
// Open an existing file.
try {
@@ -398,20 +418,15 @@ public class H5Ex_T_CompoundAttribute {
e.printStackTrace();
}
- // allocate memory for read buffer.
- dset_data = new byte[(int)dims[0] * (int)Sensor_Datatype.getDataSize()];
-
- object_data2 = new Sensor[(int)dims[0]];
+ ArrayList[] object_data = new ArrayList[(int)dims[0]];
// Read data.
try {
if ((attribute_id >= 0) && (memtype_id >= 0))
- H5.H5Aread(attribute_id, memtype_id, dset_data);
+ H5.H5AreadVL(attribute_id, memtype_id, (Object[])object_data);
- ByteBuffer inBuf = ByteBuffer.wrap(dset_data);
- inBuf.order(ByteOrder.nativeOrder());
for (int indx = 0; indx < (int)dims[0]; indx++) {
- object_data2[indx] = new Sensor(inBuf, indx * (int)Sensor_Datatype.getDataSize());
+ object_data2[indx] = new Sensor(object_data[indx]);
}
}
catch (Exception e) {
diff --git a/java/examples/datatypes/H5Ex_T_VLString.java b/java/examples/datatypes/H5Ex_T_VLString.java
index 1d4c2c4..a9288a4 100644
--- a/java/examples/datatypes/H5Ex_T_VLString.java
+++ b/java/examples/datatypes/H5Ex_T_VLString.java
@@ -74,8 +74,8 @@ public class H5Ex_T_VLString {
// Write the data to the dataset.
try {
if (dataset_id >= 0)
- H5.H5Dwrite_VLStrings(dataset_id, type_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, str_data);
+ H5.H5DwriteVL(dataset_id, type_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, str_data);
}
catch (Exception e) {
e.printStackTrace();
@@ -109,8 +109,8 @@ public class H5Ex_T_VLString {
try {
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
type_id = H5.H5Dget_type(dataset_id);
- H5.H5Dread_VLStrings(dataset_id, type_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, str_data);
+ H5.H5DreadVL(dataset_id, type_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, str_data);
}
catch (Exception e) {
e.printStackTrace();
diff --git a/java/src/jni/h5aImp.c b/java/src/jni/h5aImp.c
index 71caf76..07ecdb8 100644
--- a/java/src/jni/h5aImp.c
+++ b/java/src/jni/h5aImp.c
@@ -1115,7 +1115,8 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
H5T_class_t type_class;
jsize vl_array_len;
htri_t vl_data_class;
- herr_t status = FAIL;
+ herr_t status = FAIL;
+ htri_t is_variable = 0;
UNUSED(clss);
@@ -1124,10 +1125,11 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
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 ((is_variable = H5Tis_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
@@ -1154,7 +1156,10 @@ done:
if (sid >= 0)
H5Sclose(sid);
}
-
+ if (is_variable) {
+ for (size_t i = 0; i < (size_t)vl_array_len; i++)
+ HDfree(((char **)readBuf)[i]);
+ }
HDfree(readBuf);
}
@@ -1177,7 +1182,8 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
H5T_class_t type_class;
jsize vl_array_len;
htri_t vl_data_class;
- herr_t status = FAIL;
+ herr_t status = FAIL;
+ htri_t is_variable = 0;
UNUSED(clss);
@@ -1192,6 +1198,8 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite: write buffer length < 0");
}
+ if ((is_variable = H5Tis_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
@@ -1216,6 +1224,10 @@ done:
H5Treclaim(attr_id, sid, H5P_DEFAULT, writeBuf);
}
+ if (is_variable) {
+ for (size_t i = 0; i < (size_t)vl_array_len; i++)
+ HDfree(((char **)writeBuf)[i]);
+ }
HDfree(writeBuf);
}
diff --git a/java/src/jni/h5dImp.c b/java/src/jni/h5dImp.c
index 56c5cc8..efddb96 100644
--- a/java/src/jni/h5dImp.c
+++ b/java/src/jni/h5dImp.c
@@ -1140,26 +1140,29 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
H5T_class_t type_class;
jsize vl_array_len;
htri_t vl_data_class;
- herr_t status = FAIL;
+ herr_t status = FAIL;
+ htri_t is_variable = 0;
UNUSED(clss);
if (NULL == buf)
- H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread: read buffer is NULL");
+ H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5DreadVL: 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");
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DreadVL: readBuf length < 0");
}
+ if ((is_variable = H5Tis_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
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");
+ 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 *)readBuf)) < 0)
@@ -1173,6 +1176,10 @@ done:
if (readBuf) {
if ((status >= 0) && vl_data_class)
H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf);
+ if (is_variable) {
+ for (size_t i = 0; i < (size_t)vl_array_len; i++)
+ HDfree(((char **)readBuf)[i]);
+ }
HDfree(readBuf);
}
@@ -1194,12 +1201,13 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
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;
+ herr_t status = FAIL;
+ htri_t is_variable = 0;
UNUSED(clss);
if (NULL == buf)
- H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite: write buffer is NULL");
+ H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5DwriteVL: write buffer is NULL");
if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
@@ -1207,14 +1215,16 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
/* 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");
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DwriteVL: write buffer length < 0");
}
+ if ((is_variable = H5Tis_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
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");
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5DwriteVL: failed to allocate raw VL write buffer");
if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
@@ -1229,6 +1239,10 @@ done:
if (writeBuf) {
if ((status >= 0) && vl_data_class)
H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf);
+ if (is_variable) {
+ for (size_t i = 0; i < (size_t)vl_array_len; i++)
+ HDfree(((char **)writeBuf)[i]);
+ }
HDfree(writeBuf);
}
diff --git a/java/src/jni/h5util.c b/java/src/jni/h5util.c
index 4e62085..77fb244 100644
--- a/java/src/jni/h5util.c
+++ b/java/src/jni/h5util.c
@@ -77,6 +77,10 @@ static int render_bin_output_region_data_points(FILE *stream, hid_t region_sp
hsize_t *ptdata);
static int render_bin_output_region_points(FILE *stream, hid_t region_space, hid_t region_id,
hid_t container);
+jobject translate_atomic_rbuf(JNIEnv *env, jobject ret_buf, jlong mem_type_id, H5T_class_t type_class,
+ void *raw_buf);
+void translate_atomic_wbuf(JNIEnv *env, jobject in_obj, jlong mem_type_id, H5T_class_t type_class,
+ void *raw_buf);
/* Strings for output */
#define H5_TOOLS_GROUP "GROUP"
@@ -4040,16 +4044,20 @@ 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)
+jobject
+translate_atomic_rbuf(JNIEnv *env, jobject ret_buf, jlong mem_type_id, H5T_class_t type_class, void *raw_buf)
{
- herr_t status = FAIL;
- hid_t memb = H5I_INVALID_HID;
- H5T_class_t vlClass;
- size_t vlSize;
- size_t i, x;
- size_t typeSize;
+ jobject jobj = NULL;
+ hid_t memb = H5I_INVALID_HID;
+ int ret_buflen = -1;
+ jboolean found_jList = JNI_TRUE;
+ jobjectArray jList = NULL;
+ H5T_class_t vlClass;
+ size_t vlSize;
+ size_t i, x;
+ size_t typeSize;
+ // raw_buf is normally bytes except when used for variable length strings
+ char *char_buf = (char *)raw_buf;
/* retrieve the java.util.ArrayList interface class */
jclass arrCList = ENVPTR->FindClass(ENVONLY, "java/util/ArrayList");
@@ -4079,6 +4087,485 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
+ ret_buflen = ENVPTR->GetArrayLength(ENVONLY, ret_buf);
+ 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 element to a list */
+ hvl_t vl_elem;
+
+ found_jList = JNI_TRUE;
+ jList = NULL;
+
+ /* Get the number of sequence elements */
+ HDmemcpy(&vl_elem, char_buf, sizeof(hvl_t));
+ jsize nelmts = (jsize)vl_elem.len;
+ if (vl_elem.len != (size_t)nelmts)
+ H5_JNI_FATAL_ERROR(ENVONLY, "translate_atomic_rbuf: overflow of number of VL elements");
+
+ if (nelmts < 0)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "translate_atomic_rbuf: number of VL elements < 0");
+
+ /* The list we're going to return: */
+ if (NULL == (jList = (jobjectArray)ENVPTR->NewObject(ENVONLY, arrCList, arrListMethod, 0)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_rbuf: failed to allocate list read buffer");
+
+ translate_rbuf(ENVONLY, jList, memb, vlClass, (jsize)nelmts, vl_elem.p);
+ jobj = jList;
+ break;
+ } /* H5T_VLEN */
+ case H5T_COMPOUND: {
+ int nmembs = H5Tget_nmembers(mem_type_id);
+ void *objBuf = NULL;
+
+ /* The list we're going to return: */
+ if (NULL == (jList = (jobjectArray)ENVPTR->NewObject(ENVONLY, arrCList, arrListMethod, 0)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_rbuf: failed to allocate list read buffer");
+
+ /* Convert each element to a compound object */
+ for (i = 0; i < (size_t)nmembs; i++) {
+ H5T_class_t memb_vlClass;
+ size_t memb_vlSize;
+ size_t memb_offset;
+
+ if ((memb = H5Tget_member_type(mem_type_id, (unsigned int)i)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((memb_offset = H5Tget_member_offset(mem_type_id, (unsigned int)i)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((memb_vlClass = H5Tget_class(memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(memb_vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ translate_atomic_rbuf(ENVONLY, jList, memb, memb_vlClass,
+ char_buf + i * typeSize + memb_offset);
+ H5Tclose(memb);
+ }
+ jobj = jList;
+ break;
+ } /* H5T_COMPOUND */
+ case H5T_ARRAY: {
+ void *objBuf = NULL;
+ size_t typeCount;
+
+ 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);
+
+ typeCount = typeSize / vlSize;
+
+ if (NULL == (objBuf = HDmalloc(typeSize)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_rbuf: failed to allocate buffer");
+
+ /* Convert each element */
+ /* Get the object element */
+ HDmemcpy((char *)objBuf, char_buf, typeSize);
+
+ /* The list we're going to return: */
+ if (NULL == (jList = (jobjectArray)ENVPTR->NewObject(ENVONLY, arrCList, arrListMethod, 0)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_rbuf: failed to allocate list read buffer");
+
+ translate_rbuf(ENVONLY, jList, memb, vlClass, (jsize)typeCount, objBuf);
+ jobj = jList;
+
+ if (objBuf)
+ HDfree(objBuf);
+
+ break;
+ } /* H5T_ARRAY */
+ case H5T_ENUM:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_INTEGER: {
+ /* Convert each element */
+ switch (typeSize) {
+ case sizeof(jbyte): {
+ jbyte byteValue;
+ HDmemcpy(((char *)&byteValue), char_buf, typeSize);
+
+ if (NULL ==
+ (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cByte, byteValueMid, byteValue)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ case sizeof(jshort): {
+ jshort shortValue;
+ HDmemcpy(((char *)&shortValue), char_buf, typeSize);
+
+ if (NULL ==
+ (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cShort, shortValueMid, shortValue)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ case sizeof(jint): {
+ jint intValue;
+
+ HDmemcpy(((char *)&intValue), char_buf, typeSize);
+
+ if (NULL == (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cInt, intValueMid, intValue)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ case sizeof(jlong): {
+ jlong longValue;
+ HDmemcpy(((char *)&longValue), char_buf, typeSize);
+
+ if (NULL ==
+ (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cLong, longValueMid, longValue)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ }
+ break;
+ } /* H5T_INTEGER */
+ case H5T_FLOAT: {
+ /* Convert each element to a list */
+ switch (typeSize) {
+ case sizeof(jfloat): {
+ jfloat floatValue;
+ HDmemcpy(((char *)&floatValue), char_buf, typeSize);
+
+ if (NULL == (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cFloat, floatValueMid,
+ (double)floatValue)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ case sizeof(jdouble): {
+ jdouble doubleValue;
+ HDmemcpy(((char *)&doubleValue), char_buf, typeSize);
+
+ if (NULL == (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cDouble, doubleValueMid,
+ doubleValue)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ }
+ break;
+ } /* H5T_FLOAT */
+ case H5T_REFERENCE: {
+ /* Convert each element to a list */
+ jboolean bb;
+ jbyte *barray = NULL;
+
+ jsize byteArraySize = (jsize)typeSize;
+ if (typeSize != (size_t)byteArraySize)
+ H5_JNI_FATAL_ERROR(ENVONLY, "translate_atomic_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_atomic_rbuf reference: byte array not pinned");
+
+ HDmemcpy(barray, ((jbyte *)raw_buf), typeSize);
+ if (barray)
+ UNPIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, jobj ? 0 : JNI_ABORT);
+
+ break;
+ } /* H5T_REFERENCE */
+ case H5T_STRING: {
+ htri_t is_variable = 0;
+
+ if ((is_variable = H5Tis_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ /* Convert each element */
+ if (is_variable) {
+ char **var_str_buf = (char **)raw_buf;
+ if (NULL == (jobj = ENVPTR->NewStringUTF(ENVONLY, *var_str_buf))) {
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_rbuf: out of memory - unable to "
+ "construct string from UTF characters");
+ }
+ }
+ else {
+ if (NULL == (jobj = ENVPTR->NewStringUTF(ENVONLY, char_buf))) {
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_rbuf: out of memory - unable to "
+ "construct string from UTF characters");
+ }
+ }
+
+ break;
+ } /* H5T_STRING */
+ default:
+ H5_UNIMPLEMENTED(ENVONLY, "translate_atomic_rbuf: invalid class type");
+ break;
+ } /* switch(type_class) */
+
+done:
+
+ return jobj;
+}
+
+void
+translate_atomic_wbuf(JNIEnv *env, jobject in_obj, jlong mem_type_id, H5T_class_t type_class, void *raw_buf)
+{
+ hid_t memb = H5I_INVALID_HID;
+ H5T_class_t vlClass;
+ size_t vlSize;
+ size_t i, x;
+ size_t typeSize;
+ // raw_buf is normally bytes except when used for variable length strings
+ char *char_buf = (char *)raw_buf;
+
+ /* 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 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 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 (!(typeSize = H5Tget_size(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ 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);
+
+ /* Convert element to a vlen element */
+ hvl_t vl_elem;
+
+ jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, in_obj);
+
+ if (jnelmts < 0)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "translate_atomic_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_atomic_wbuf: failed to allocate vlen ptr buffer");
+
+ translate_wbuf(ENVONLY, (jobjectArray)in_obj, memb, vlClass, (jsize)jnelmts, vl_elem.p);
+
+ HDmemcpy(char_buf, &vl_elem, sizeof(hvl_t));
+ break;
+ } /* H5T_VLEN */
+ case H5T_COMPOUND: {
+ void *objBuf = NULL;
+
+ /* Convert each compound element */
+ int nmembs = H5Tget_nmembers(mem_type_id);
+
+ /* invoke the toArray method */
+ if (mToArray == NULL)
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ jobjectArray array = (jobjectArray)ENVPTR->CallObjectMethod(ENVONLY, in_obj, mToArray);
+ jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, array);
+
+ if (jnelmts != nmembs)
+ H5_BAD_ARGUMENT_ERROR(
+ ENVONLY, "translate_atomic_wbuf: number of elements not equal to number of members");
+
+ /* Convert each compound object to an element */
+ for (i = 0; i < (size_t)nmembs; i++) {
+ H5T_class_t memb_vlClass;
+ size_t memb_vlSize;
+ size_t memb_offset;
+
+ if ((memb = H5Tget_member_type(mem_type_id, (unsigned int)i)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((memb_offset = H5Tget_member_offset(mem_type_id, (unsigned int)i)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((memb_vlClass = H5Tget_class(memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(memb_vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ jobject arr_obj = ENVPTR->GetObjectArrayElement(ENVONLY, array, i);
+ translate_atomic_wbuf(ENVONLY, arr_obj, memb, memb_vlClass,
+ char_buf + i * typeSize + memb_offset);
+ ENVPTR->DeleteLocalRef(ENVONLY, arr_obj);
+ H5Tclose(memb);
+ }
+ 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 array element */
+ /* invoke the toArray method */
+ if (mToArray == NULL)
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ jobjectArray array = (jobjectArray)ENVPTR->CallObjectMethod(ENVONLY, in_obj, mToArray);
+ jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, array);
+
+ if (jnelmts < 0)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "translate_atomic_wbuf: number of array elements < 0");
+
+ if (NULL == (objBuf = HDmalloc((size_t)jnelmts * vlSize)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_wbuf: failed to allocate buffer");
+
+ translate_wbuf(ENVONLY, array, memb, vlClass, (jsize)jnelmts, objBuf);
+
+ HDmemcpy(char_buf, (char *)objBuf, vlSize * jnelmts);
+ break;
+ } /* H5T_ARRAY */
+ case H5T_ENUM:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_INTEGER: {
+ /* Convert each element */
+ switch (typeSize) {
+ case sizeof(jbyte): {
+ jbyte byteValue = ENVPTR->CallByteMethod(ENVONLY, in_obj, byteValueMid);
+ HDmemcpy(char_buf, ((char *)&byteValue), typeSize);
+ }
+ case sizeof(jshort): {
+ jshort shortValue = ENVPTR->CallShortMethod(ENVONLY, in_obj, shortValueMid);
+ HDmemcpy(char_buf, ((char *)&shortValue), typeSize);
+ break;
+ }
+ case sizeof(jint): {
+ jint intValue = ENVPTR->CallIntMethod(ENVONLY, in_obj, intValueMid);
+ HDmemcpy(char_buf, ((char *)&intValue), typeSize);
+ break;
+ }
+ case sizeof(jlong): {
+ jlong longValue = ENVPTR->CallLongMethod(ENVONLY, in_obj, longValueMid);
+ HDmemcpy(char_buf, ((char *)&longValue), typeSize);
+ break;
+ }
+ }
+ break;
+ } /* H5T_INTEGER */
+ case H5T_FLOAT: {
+ /* Convert each element */
+ switch (typeSize) {
+ case sizeof(jfloat): {
+ jfloat floatValue = ENVPTR->CallFloatMethod(ENVONLY, in_obj, floatValueMid);
+ HDmemcpy(char_buf, ((char *)&floatValue), typeSize);
+ break;
+ }
+ case sizeof(jdouble): {
+ jdouble doubleValue = ENVPTR->CallDoubleMethod(ENVONLY, in_obj, doubleValueMid);
+ HDmemcpy(char_buf, ((char *)&doubleValue), typeSize);
+ break;
+ }
+ }
+ break;
+ } /* H5T_FLOAT */
+ case H5T_REFERENCE: {
+ /* Convert each array element */
+ jbyte *barray = (jbyte *)ENVPTR->GetByteArrayElements(ENVONLY, in_obj, 0);
+ HDmemcpy(char_buf, ((char *)barray), typeSize);
+ ENVPTR->ReleaseByteArrayElements(ENVONLY, in_obj, barray, 0);
+ break;
+ } /* H5T_REFERENCE */
+ case H5T_STRING: {
+ htri_t is_variable = 0;
+
+ if ((is_variable = H5Tis_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ /* Convert each pointer element */
+ jsize length;
+ const char *utf8 = NULL;
+
+ HDmemset(char_buf, 0, typeSize);
+ if (NULL != in_obj) {
+ PIN_JAVA_STRING(ENVONLY, in_obj, utf8, NULL, "translate_atomic_wbuf jobj not pinned");
+ length = ENVPTR->GetStringUTFLength(ENVONLY, in_obj);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ if (is_variable) {
+ char *new_buf = (char *)HDcalloc((size_t)1, length + 1);
+ HDmemcpy(((char *)new_buf), utf8, length);
+ HDmemcpy(char_buf, &new_buf, typeSize);
+ }
+ else {
+ HDmemcpy(char_buf, utf8, length);
+ }
+ UNPIN_JAVA_STRING(ENVONLY, in_obj, utf8);
+ utf8 = NULL;
+ }
+ break;
+ } /* H5T_STRING */
+ default:
+ H5_UNIMPLEMENTED(ENVONLY, "translate_atomic_wbuf: invalid class type");
+ break;
+ } /* switch(type_class) */
+
+done:
+
+ return;
+}
+
+void
+translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t type_class, jsize count,
+ void *raw_buf)
+{
+ hid_t memb = H5I_INVALID_HID;
+ int ret_buflen = -1;
+ jboolean found_jList = JNI_TRUE;
+ jobjectArray jList = NULL;
+ jobject jobj = NULL;
+ H5T_class_t vlClass;
+ size_t vlSize;
+ size_t i, x;
+ size_t typeSize;
+ // raw_buf is normally bytes except when used for variable length strings
+ char *char_buf = (char *)raw_buf;
+
+ /* 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 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 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 (!(typeSize = H5Tget_size(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ ret_buflen = ENVPTR->GetArrayLength(ENVONLY, ret_buf);
switch (type_class) {
case H5T_VLEN: {
if (!(memb = H5Tget_super(mem_type_id)))
@@ -4090,13 +4577,13 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
/* 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;
+ hvl_t vl_elem;
+
+ found_jList = JNI_TRUE;
+ jList = NULL;
/* Get the number of sequence elements */
- HDmemcpy(&vl_elem, (char *)raw_buf + i * sizeof(hvl_t), sizeof(hvl_t));
+ HDmemcpy(&vl_elem, char_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");
@@ -4104,7 +4591,6 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
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);
@@ -4125,64 +4611,70 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
if (!addResult)
H5_JNI_FATAL_ERROR(ENVONLY, "translate_rbuf: cannot add VL element");
}
+ else {
+ ENVPTR->SetObjectArrayElement(ENVONLY, ret_buf, i, (jobject)jList);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ }
ENVPTR->DeleteLocalRef(ENVONLY, jList);
}
break;
} /* H5T_VLEN */
case H5T_COMPOUND: {
- int nmembs = H5Tget_nmembers(mem_type_id);
- void *objBuf = NULL;
- size_t offset;
-
- 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 (nmembs < 0)
- goto done;
-
- /* 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;
-
- 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);
+ void *objBuf = NULL;
- /* Get the object element */
- HDmemcpy(&objBuf, (char *)raw_buf + offset, vlSize);
+ /* Convert each compound element to a list */
+ for (i = 0; i < (size_t)count; i++) {
+ found_jList = JNI_TRUE;
+ jList = NULL;
- 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;
+ 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");
}
+ int nmembs = H5Tget_nmembers(mem_type_id);
+ /* Convert each element to a list */
+ for (x = 0; x < (size_t)nmembs; x++) {
+ H5T_class_t memb_vlClass;
+ size_t memb_vlSize;
+ size_t memb_offset;
+
+ if ((memb = H5Tget_member_type(mem_type_id, (unsigned int)x)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((memb_offset = H5Tget_member_offset(mem_type_id, (unsigned int)x)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
- translate_rbuf(ENVONLY, jList, memb, vlClass, (jsize)1, objBuf);
- if (!found_jList) {
- ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jList);
- ENVPTR->DeleteLocalRef(ENVONLY, jList);
+ if ((memb_vlClass = H5Tget_class(memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(memb_vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ jobj = translate_atomic_rbuf(ENVONLY, jList, memb, memb_vlClass,
+ char_buf + i * typeSize + memb_offset);
+ if (jobj) {
+ if (found_jList == JNI_FALSE)
+ ENVPTR->CallBooleanMethod(ENVONLY, jList, arrAddMethod, (jobject)jobj);
+ else
+ ENVPTR->SetObjectArrayElement(ENVONLY, jList, i, (jobject)jobj);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ ENVPTR->DeleteLocalRef(ENVONLY, jobj);
+ }
+
+ H5Tclose(memb);
}
+ if (ret_buflen == 0)
+ ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jList);
+ else
+ ENVPTR->SetObjectArrayElement(ENVONLY, ret_buf, i, jList);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ ENVPTR->DeleteLocalRef(ENVONLY, jList);
}
- H5Tclose(memb);
break;
} /* H5T_COMPOUND */
case H5T_ARRAY: {
@@ -4195,7 +4687,6 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
H5_LIBRARY_ERROR(ENVONLY);
if (!(vlSize = H5Tget_size(memb)))
H5_LIBRARY_ERROR(ENVONLY);
-
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
@@ -4206,14 +4697,12 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
/* 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;
+ found_jList = JNI_TRUE;
+ jList = NULL;
/* Get the object element */
- HDmemcpy((char *)objBuf, (char *)raw_buf + i * typeSize, typeSize);
+ HDmemcpy((char *)objBuf, char_buf + i * typeSize, typeSize);
- ret_buflen = ENVPTR->GetArrayLength(ENVONLY, ret_buf);
/* The list we're going to return: */
if (i < ret_buflen) {
if (NULL ==
@@ -4228,10 +4717,12 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
}
translate_rbuf(ENVONLY, jList, memb, vlClass, (jsize)typeCount, objBuf);
- if (!found_jList) {
+ if (found_jList == JNI_FALSE)
ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jList);
- ENVPTR->DeleteLocalRef(ENVONLY, jList);
- }
+ else
+ ENVPTR->SetObjectArrayElement(ENVONLY, ret_buf, i, jList);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ ENVPTR->DeleteLocalRef(ENVONLY, jList);
}
if (objBuf)
@@ -4239,130 +4730,28 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
break;
} /* H5T_ARRAY */
- case H5T_INTEGER: {
- /* Convert each element to a list */
- for (i = 0; i < (size_t)count; i++) {
- jobject jobj = NULL;
- switch (typeSize) {
- case sizeof(jbyte): {
- jbyte byteValue;
- for (x = 0; x < typeSize; x++) {
- ((char *)&byteValue)[x] = ((char *)raw_buf)[i * typeSize + x];
- }
-
- if (NULL ==
- (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cByte, byteValueMid, byteValue)))
- 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 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 sizeof(jlong): {
- jlong longValue;
- for (x = 0; x < typeSize; x++) {
- ((char *)&longValue)[x] = ((char *)raw_buf)[i * typeSize + x];
- }
-
- if (NULL ==
- (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cLong, longValueMid, longValue)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- 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 (NULL == (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cFloat, floatValueMid,
- (double)floatValue)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- 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;
- }
- }
- if (jobj) {
- ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jobj);
- ENVPTR->DeleteLocalRef(ENVONLY, jobj);
- }
- }
- break;
- } /* H5T_FLOAT */
- case H5T_REFERENCE: {
+ case H5T_ENUM:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_INTEGER:
+ case H5T_FLOAT:
+ case H5T_REFERENCE:
+ case H5T_STRING: {
/* Convert each element to a list */
for (i = 0; i < (size_t)count; i++) {
- jboolean bb;
- jbyte *barray = NULL;
- jobject jobj = NULL;
-
- 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);
-
+ jobj =
+ translate_atomic_rbuf(ENVONLY, ret_buf, mem_type_id, type_class, char_buf + i * typeSize);
if (jobj) {
- ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jobj);
+ if (ret_buflen == 0)
+ ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, (jobject)jobj);
+ else
+ ENVPTR->SetObjectArrayElement(ENVONLY, ret_buf, i, (jobject)jobj);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
ENVPTR->DeleteLocalRef(ENVONLY, jobj);
}
}
break;
- } /* H5T_REFERENCE */
+ }
default:
H5_UNIMPLEMENTED(ENVONLY, "translate_rbuf: invalid class type");
break;
@@ -4370,21 +4759,22 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
done:
- return (jint)status;
+ return;
}
-herr_t
+void
translate_wbuf(JNIEnv *env, jobjectArray in_buf, jlong mem_type_id, H5T_class_t type_class, jsize count,
- jbyte *raw_buf)
+ void *raw_buf)
{
- herr_t status = FAIL;
- hid_t memb = H5I_INVALID_HID;
- jobjectArray jList = NULL;
- jobject jobj = NULL;
+ hid_t memb = H5I_INVALID_HID;
+ jobjectArray jList = NULL;
+ jobject jobj = NULL;
H5T_class_t vlClass;
size_t vlSize;
size_t i, x;
size_t typeSize;
+ // raw_buf is normally bytes except when used for variable length strings
+ char *char_buf = (char *)raw_buf;
/* retrieve the java.util.ArrayList interface class */
jclass arrCList = ENVPTR->FindClass(ENVONLY, "java/util/ArrayList");
@@ -4441,16 +4831,59 @@ translate_wbuf(JNIEnv *env, jobjectArray in_buf, jlong mem_type_id, H5T_class_t
if (NULL == (vl_elem.p = HDmalloc((size_t)jnelmts * vlSize)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_wbuf: failed to allocate vlen ptr buffer");
- translate_wbuf(ENVONLY, (jobjectArray)array, memb, vlClass, (jsize)jnelmts, vl_elem.p);
+ translate_wbuf(ENVONLY, array, memb, vlClass, (jsize)jnelmts, vl_elem.p);
- HDmemcpy((char *)raw_buf + i * sizeof(hvl_t), &vl_elem, sizeof(hvl_t));
+ HDmemcpy(char_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");
+ void *objBuf = NULL;
+
+ /* Convert each list to a compound 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);
+
+ int nmembs = H5Tget_nmembers(mem_type_id);
+
+ /* 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 != nmembs)
+ H5_BAD_ARGUMENT_ERROR(
+ ENVONLY, "translate_wbuf: number of elements not equal to number of members");
+
+ /* Convert each compound object to an element */
+ for (x = 0; x < (size_t)nmembs; x++) {
+ H5T_class_t memb_vlClass;
+ size_t memb_vlSize;
+ size_t memb_offset;
+
+ if ((memb = H5Tget_member_type(mem_type_id, (unsigned int)x)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((memb_offset = H5Tget_member_offset(mem_type_id, (unsigned int)x)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ if ((memb_vlClass = H5Tget_class(memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(memb_vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ jobject arr_obj = ENVPTR->GetObjectArrayElement(ENVONLY, array, x);
+ translate_atomic_wbuf(ENVONLY, arr_obj, memb, memb_vlClass,
+ char_buf + i * typeSize + memb_offset);
+ ENVPTR->DeleteLocalRef(ENVONLY, arr_obj);
+ H5Tclose(memb);
+ }
+
+ ENVPTR->DeleteLocalRef(ENVONLY, jList);
+ } /* end for (i = 0; i < count; i++) */
break;
} /* H5T_COMPOUND */
case H5T_ARRAY: {
@@ -4477,91 +4910,25 @@ translate_wbuf(JNIEnv *env, jobjectArray in_buf, jlong mem_type_id, H5T_class_t
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);
+ translate_wbuf(ENVONLY, array, memb, vlClass, (jsize)jnelmts,
+ char_buf + i * vlSize * jnelmts); // objBuf);
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];
- }
- 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];
- }
- 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];
- }
- 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);
- }
- 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: {
+ case H5T_ENUM:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_INTEGER:
+ case H5T_FLOAT:
+ case H5T_REFERENCE:
+ case H5T_STRING: {
/* 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);
+ translate_atomic_wbuf(ENVONLY, jobj, mem_type_id, type_class, char_buf + i * typeSize);
ENVPTR->DeleteLocalRef(ENVONLY, jobj);
}
break;
@@ -4573,7 +4940,7 @@ translate_wbuf(JNIEnv *env, jobjectArray in_buf, jlong mem_type_id, H5T_class_t
done:
- return (jint)status;
+ return;
}
#ifdef __cplusplus
diff --git a/java/src/jni/h5util.h b/java/src/jni/h5util.h
index 27c9178..d8ecef9 100644
--- a/java/src/jni/h5util.h
+++ b/java/src/jni/h5util.h
@@ -51,10 +51,10 @@ 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);
+extern void translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t type_class,
+ jsize count, void *raw_buf);
+extern void translate_wbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t type_class,
+ jsize count, void *raw_buf);
/*
* Symbols used to format the output of h5str_sprintf and
diff --git a/java/test/TestH5A.java b/java/test/TestH5A.java
index d17e16c..90fe24c 100644
--- a/java/test/TestH5A.java
+++ b/java/test/TestH5A.java
@@ -46,6 +46,7 @@ public class TestH5A {
private static final int DIM_Y = 6;
long H5fid = HDF5Constants.H5I_INVALID_HID;
long H5dsid = HDF5Constants.H5I_INVALID_HID;
+ long H5atid = HDF5Constants.H5I_INVALID_HID;
long H5did = HDF5Constants.H5I_INVALID_HID;
long[] H5dims = {DIM_X, DIM_Y};
long type_id = HDF5Constants.H5I_INVALID_HID;
@@ -136,8 +137,12 @@ public class TestH5A {
}
catch (Exception ex) {
}
-
- _deleteFile(H5_FILE);
+ if (H5atid > 0)
+ try {
+ H5.H5Tclose(H5atid);
+ }
+ catch (Exception ex) {
+ }
if (type_id > 0)
try {
@@ -163,6 +168,8 @@ public class TestH5A {
}
catch (Exception ex) {
}
+
+ _deleteFile(H5_FILE);
System.out.println();
}
@@ -1072,7 +1079,7 @@ public class TestH5A {
HDF5Constants.H5P_DEFAULT);
assertTrue("testH5Awrite_readVL: ", attr_id >= 0);
- H5.H5Awrite_VLStrings(attr_id, atype_id, str_data);
+ H5.H5AwriteVL(attr_id, atype_id, str_data);
H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
@@ -1084,7 +1091,7 @@ public class TestH5A {
strs[j] = "";
}
try {
- H5.H5Aread_VLStrings(attr_id, atype_id, strs);
+ H5.H5AreadVL(attr_id, atype_id, strs);
}
catch (Exception ex) {
ex.printStackTrace();
@@ -1863,4 +1870,134 @@ public class TestH5A {
}
}
}
+
+ @Test
+ public void testH5AArray_string_buffer() throws Throwable
+ {
+ String att_str_name = "ArrayStringdata";
+ long att_str_id = HDF5Constants.H5I_INVALID_HID;
+ long atype_str_id = HDF5Constants.H5I_INVALID_HID;
+ long aspace_id = HDF5Constants.H5I_INVALID_HID;
+ long[] strdims = {4};
+ long[] dims = {6};
+ long lsize = 1;
+
+ String[] str_data0 = {"Parting", "is such", "sweet", "sorrow."};
+ String[] str_data1 = {"Testing", "one", "two", "three."};
+ String[] str_data2 = {"Dog,", "man's", "best", "friend."};
+ String[] str_data3 = {"Diamonds", "are", "a", "girls!"};
+ String[] str_data4 = {"S A", "T U R", "D A Y", "night"};
+ String[] str_data5 = {"That's", "all", "folks", "!!!"};
+
+ ArrayList[] arr_str_data = new ArrayList[6];
+ arr_str_data[0] = new ArrayList<String>(Arrays.asList(str_data0));
+ arr_str_data[1] = new ArrayList<String>(Arrays.asList(str_data1));
+ arr_str_data[2] = new ArrayList<String>(Arrays.asList(str_data2));
+ arr_str_data[3] = new ArrayList<String>(Arrays.asList(str_data3));
+ arr_str_data[4] = new ArrayList<String>(Arrays.asList(str_data4));
+ arr_str_data[5] = new ArrayList<String>(Arrays.asList(str_data5));
+
+ try {
+ H5atid = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5AArray_string_buffer.H5.H5Tcopy: " + err);
+ }
+ assertTrue("testH5AArray_string_buffer.H5Tcopy: ", H5atid >= 0);
+ try {
+ H5.H5Tset_size(H5atid, HDF5Constants.H5T_VARIABLE);
+ assertTrue("testH5AArray_string_buffer.H5Tis_variable_str", H5.H5Tis_variable_str(H5atid));
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5DArray_string_buffer.H5Tset_size: " + err);
+ }
+ try {
+ atype_str_id = H5.H5Tarray_create(H5atid, 1, strdims);
+ assertTrue("testH5AArray_string_buffer.H5Tarray_create: ", atype_str_id >= 0);
+ }
+ catch (Exception err) {
+ if (atype_str_id > 0)
+ try {
+ H5.H5Tclose(atype_str_id);
+ }
+ catch (Exception ex) {
+ }
+ err.printStackTrace();
+ fail("testH5AArray_string_buffer: " + err);
+ }
+
+ try {
+ aspace_id = H5.H5Screate_simple(1, dims, null);
+ assertTrue(aspace_id > 0);
+ att_str_id = H5.H5Acreate(H5did, att_str_name, atype_str_id, aspace_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5AArray_string_buffer: ", att_str_id >= 0);
+
+ H5.H5AwriteVL(att_str_id, atype_str_id, arr_str_data);
+ }
+ catch (Exception err) {
+ if (att_str_id > 0)
+ try {
+ H5.H5Dclose(att_str_id);
+ }
+ catch (Exception ex) {
+ }
+ if (atype_str_id > 0)
+ try {
+ H5.H5Tclose(atype_str_id);
+ }
+ catch (Exception ex) {
+ }
+ err.printStackTrace();
+ fail("testH5AArray_string_buffer: " + 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];
+
+ ArrayList[] arr_readbuf = new ArrayList[6];
+ for (int j = 0; j < lsize; j++)
+ arr_readbuf[j] = new ArrayList<String>();
+
+ try {
+ H5.H5AreadVL(att_str_id, atype_str_id, arr_readbuf);
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ finally {
+ if (att_str_id > 0)
+ try {
+ H5.H5Aclose(att_str_id);
+ }
+ catch (Exception ex) {
+ }
+ if (atype_str_id > 0)
+ try {
+ H5.H5Tclose(atype_str_id);
+ }
+ catch (Exception ex) {
+ }
+ }
+ assertTrue("testH5AArray_string_buffer:" + arr_readbuf[0].get(0),
+ arr_str_data[0].get(0).equals(arr_readbuf[0].get(0)));
+ assertTrue("testH5AArray_string_buffer:" + arr_readbuf[1].get(0),
+ arr_str_data[1].get(0).equals(arr_readbuf[1].get(0)));
+ assertTrue("testH5AArray_string_buffer:" + arr_readbuf[2].get(0),
+ arr_str_data[2].get(0).equals(arr_readbuf[2].get(0)));
+ assertTrue("testH5AArray_string_buffer:" + arr_readbuf[3].get(0),
+ arr_str_data[3].get(0).equals(arr_readbuf[3].get(0)));
+ }
}
diff --git a/java/test/TestH5D.java b/java/test/TestH5D.java
index f204e38..eacaabf 100644
--- a/java/test/TestH5D.java
+++ b/java/test/TestH5D.java
@@ -158,7 +158,7 @@ public class TestH5D {
assertTrue("TestH5D._createDataset.H5Dcreate: ", H5did >= 0);
}
- private final void _createVLDataset(long fid, long dsid, String name, long dapl)
+ private final void _createVLStrDataset(String name, long dapl)
{
try {
H5dtid = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
@@ -167,24 +167,24 @@ public class TestH5D {
err.printStackTrace();
fail("H5.H5Tcopy: " + err);
}
- assertTrue("TestH5D._createVLDataset.H5Tcopy: ", H5dtid >= 0);
+ assertTrue("TestH5D._createVLStrDataset.H5Tcopy: ", H5dtid >= 0);
try {
H5.H5Tset_size(H5dtid, HDF5Constants.H5T_VARIABLE);
- assertTrue("TestH5D._createVLDataset.H5Tis_variable_str", H5.H5Tis_variable_str(H5dtid));
+ assertTrue("TestH5D._createVLStrDataset.H5Tis_variable_str", H5.H5Tis_variable_str(H5dtid));
}
catch (Throwable err) {
err.printStackTrace();
fail("H5.H5Tset_size: " + err);
}
try {
- H5did = H5.H5Dcreate(fid, name, H5dtid, dsid, HDF5Constants.H5P_DEFAULT,
+ H5did = H5.H5Dcreate(H5fid, name, H5dtid, H5dsid, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT, dapl);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5.H5Dcreate: " + err);
}
- assertTrue("TestH5D._createVLDataset.H5Dcreate: ", H5did >= 0);
+ assertTrue("TestH5D._createVLStrDataset.H5Dcreate: ", H5did >= 0);
}
private final void _closeH5file() throws HDF5LibraryException
@@ -935,7 +935,7 @@ public class TestH5D {
buf_data[(indx * DIM_Y) + jndx] == 126);
}
- @Test
+ @Ignore
public void testH5Dvlen_get_buf_size()
{
String[] str_data = {"Parting", "is such", "sweet", "sorrow.", "Testing", "one", "two", "three.",
@@ -946,12 +946,12 @@ public class TestH5D {
for (int idx = 0; idx < str_data.length; idx++)
str_data_bytes += str_data[idx].length() + 1; // Account for terminating null
- _createVLDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+ _createVLStrDataset("dset", HDF5Constants.H5P_DEFAULT);
try {
if ((H5did >= 0) && (H5dtid >= 0))
- H5.H5Dwrite_VLStrings(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, str_data);
+ H5.H5DwriteVL(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, str_data);
}
catch (Exception e) {
e.printStackTrace();
@@ -966,25 +966,121 @@ public class TestH5D {
}
@Ignore
- public void testH5Dvlen_read_default_buffer() throws Throwable
+ public void testH5Dvlen_string_buffer() throws Throwable
{
- String[] str_data = {"Parting", "is such", "sweet", "sorrow.", "Testing", "one", "two", "three.",
- "Dog,", "man's", "best", "friend.", "Diamonds", "are", "a", "girls!",
- "S A", "T U R", "D A Y", "night", "That's", "all", "folks", "!!!"};
- byte[] read_data = new byte[512];
+ String dset_str_name = "VLStringdata";
+ long dset_str_id = HDF5Constants.H5I_INVALID_HID;
+ long dtype_str_id = HDF5Constants.H5I_INVALID_HID;
+ long dspace_id = HDF5Constants.H5I_INVALID_HID;
+ long[] dims = {64};
+ long lsize = 1;
- _createVLDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+ String[] str_data0 = {"Parting", "is such", "sweet", "sorrow."};
+ String[] str_data1 = {"Testing", "one", "two", "three."};
+ String[] str_data2 = {"Dog,", "man's", "best", "friend."};
+ String[] str_data3 = {"Diamonds", "are", "a", "girls!"};
+ String[] str_data4 = {"S A", "T U R", "D A Y", "night"};
+ String[] str_data5 = {"That's", "all", "folks", "!!!"};
+
+ ArrayList[] vl_str_data = new ArrayList[6];
+ vl_str_data[0] = new ArrayList<String>(Arrays.asList(str_data0));
+ vl_str_data[1] = new ArrayList<String>(Arrays.asList(str_data1));
+ vl_str_data[2] = new ArrayList<String>(Arrays.asList(str_data2));
+ vl_str_data[3] = new ArrayList<String>(Arrays.asList(str_data3));
+ vl_str_data[4] = new ArrayList<String>(Arrays.asList(str_data4));
+ vl_str_data[5] = new ArrayList<String>(Arrays.asList(str_data5));
try {
- H5.H5Dwrite_VLStrings(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, str_data);
+ H5dtid = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
}
- catch (Exception e) {
- e.printStackTrace();
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Dvlen_string_buffer.H5.H5Tcopy: " + err);
+ }
+ assertTrue("testH5Dvlen_string_buffer.H5Tcopy: ", H5dtid >= 0);
+ try {
+ H5.H5Tset_size(H5dtid, HDF5Constants.H5T_VARIABLE);
+ assertTrue("testH5Dvlen_string_buffer.H5Tis_variable_str", H5.H5Tis_variable_str(H5dtid));
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Dvlen_string_buffer.H5Tset_size: " + err);
+ }
+ try {
+ dtype_str_id = H5.H5Tvlen_create(H5dtid);
+ assertTrue("testH5Dvlen_string_buffer.H5Tvlen_create: ", dtype_str_id >= 0);
+ }
+ catch (Exception err) {
+ if (dtype_str_id > 0)
+ try {
+ H5.H5Tclose(dtype_str_id);
+ }
+ catch (Exception ex) {
+ }
+ err.printStackTrace();
+ fail("testH5Dvlen_string_buffer: " + err);
}
- H5.H5Dread(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT,
- read_data);
+ try {
+ dspace_id = H5.H5Screate_simple(1, dims, null);
+ assertTrue(dspace_id > 0);
+ dset_str_id =
+ H5.H5Dcreate(H5fid, dset_str_name, dtype_str_id, dspace_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5Dvlen_string_buffer: ", dset_str_id >= 0);
+
+ H5.H5DwriteVL(dset_str_id, dtype_str_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, vl_str_data);
+ }
+ catch (Exception err) {
+ if (dset_str_id > 0)
+ try {
+ H5.H5Dclose(dset_str_id);
+ }
+ catch (Exception ex) {
+ }
+ if (dtype_str_id > 0)
+ try {
+ H5.H5Tclose(dtype_str_id);
+ }
+ catch (Exception ex) {
+ }
+ err.printStackTrace();
+ fail("testH5Dvlen_string_buffer: " + 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];
+
+ ArrayList[] vl_readbuf = new ArrayList[4];
+ for (int j = 0; j < lsize; j++)
+ vl_readbuf[j] = new ArrayList<String>();
+
+ try {
+ H5.H5DreadVL(dset_str_id, dtype_str_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, vl_readbuf);
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ assertTrue("testH5Dvlen_string_buffer:" + vl_readbuf[0].get(0),
+ vl_str_data[0].get(0).equals(vl_readbuf[0].get(0)));
+ assertTrue("testH5Dvlen_string_buffer:" + vl_readbuf[1].get(0),
+ vl_str_data[1].get(0).equals(vl_readbuf[1].get(0)));
+ assertTrue("testH5Dvlen_string_buffer:" + vl_readbuf[2].get(0),
+ vl_str_data[2].get(0).equals(vl_readbuf[2].get(0)));
+ assertTrue("testH5Dvlen_string_buffer:" + vl_readbuf[3].get(0),
+ vl_str_data[3].get(0).equals(vl_readbuf[3].get(0)));
}
@Test
@@ -995,20 +1091,21 @@ public class TestH5D {
"S A", "T U R", "D A Y", "night", "That's", "all", "folks", "!!!"};
String[] str_rdata = new String[DIM_X * DIM_Y];
- _createVLDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+ _createVLStrDataset("dset", HDF5Constants.H5P_DEFAULT);
try {
if ((H5did >= 0) && (H5dtid >= 0))
- H5.H5Dwrite_VLStrings(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, str_wdata);
+ H5.H5DwriteVL(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, str_wdata);
}
catch (Exception e) {
e.printStackTrace();
}
+
try {
if ((H5did >= 0) && (H5dtid >= 0))
- H5.H5Dread_VLStrings(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, str_rdata);
+ H5.H5DreadVL(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, str_rdata);
}
catch (Exception e) {
e.printStackTrace();
@@ -1158,46 +1255,46 @@ public class TestH5D {
lsize *= dims[j];
// Read Integer data
- ArrayList[] vl_readbuf = new ArrayList[4];
+ ArrayList[] vl_int_readbuf = new ArrayList[4];
for (int j = 0; j < lsize; j++)
- vl_readbuf[j] = new ArrayList<Integer>();
+ vl_int_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);
+ HDF5Constants.H5P_DEFAULT, vl_int_readbuf);
}
catch (Exception ex) {
ex.printStackTrace();
}
- assertTrue("testH5DVLwr:" + vl_readbuf[0].get(0),
- vl_int_data[0].get(0).equals(vl_readbuf[0].get(0)));
- assertTrue("testH5DVLwr:" + vl_readbuf[1].get(0),
- vl_int_data[1].get(0).equals(vl_readbuf[1].get(0)));
- assertTrue("testH5DVLwr:" + vl_readbuf[2].get(0),
- vl_int_data[2].get(0).equals(vl_readbuf[2].get(0)));
- assertTrue("testH5DVLwr:" + vl_readbuf[3].get(0),
- vl_int_data[3].get(0).equals(vl_readbuf[3].get(0)));
+ assertTrue("testH5DVLwr:" + vl_int_readbuf[0].get(0),
+ vl_int_data[0].get(0).equals(vl_int_readbuf[0].get(0)));
+ assertTrue("testH5DVLwr:" + vl_int_readbuf[1].get(0),
+ vl_int_data[1].get(0).equals(vl_int_readbuf[1].get(0)));
+ assertTrue("testH5DVLwr:" + vl_int_readbuf[2].get(0),
+ vl_int_data[2].get(0).equals(vl_int_readbuf[2].get(0)));
+ assertTrue("testH5DVLwr:" + vl_int_readbuf[3].get(0),
+ vl_int_data[3].get(0).equals(vl_int_readbuf[3].get(0)));
// Read Double data
- vl_readbuf = new ArrayList[4];
+ ArrayList[] vl_dbl_readbuf = new ArrayList[4];
for (int j = 0; j < lsize; j++)
- vl_readbuf[j] = new ArrayList<Double>();
+ vl_dbl_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);
+ HDF5Constants.H5P_DEFAULT, vl_dbl_readbuf);
}
catch (Exception ex) {
ex.printStackTrace();
}
- assertTrue("testH5DVLwr:" + vl_readbuf[0].get(0),
- vl_dbl_data[0].get(0).equals(vl_readbuf[0].get(0)));
- assertTrue("testH5DVLwr:" + vl_readbuf[1].get(0),
- vl_dbl_data[1].get(0).equals(vl_readbuf[1].get(0)));
- assertTrue("testH5DVLwr:" + vl_readbuf[2].get(0),
- vl_dbl_data[2].get(0).equals(vl_readbuf[2].get(0)));
- assertTrue("testH5DVLwr:" + vl_readbuf[3].get(0),
- vl_dbl_data[3].get(0).equals(vl_readbuf[3].get(0)));
+ assertTrue("testH5DVLwr:" + vl_dbl_readbuf[0].get(0),
+ vl_dbl_data[0].get(0).equals(vl_dbl_readbuf[0].get(0)));
+ assertTrue("testH5DVLwr:" + vl_dbl_readbuf[1].get(0),
+ vl_dbl_data[1].get(0).equals(vl_dbl_readbuf[1].get(0)));
+ assertTrue("testH5DVLwr:" + vl_dbl_readbuf[2].get(0),
+ vl_dbl_data[2].get(0).equals(vl_dbl_readbuf[2].get(0)));
+ assertTrue("testH5DVLwr:" + vl_dbl_readbuf[3].get(0),
+ vl_dbl_data[3].get(0).equals(vl_dbl_readbuf[3].get(0)));
}
catch (Throwable err) {
err.printStackTrace();
@@ -1524,4 +1621,330 @@ public class TestH5D {
}
}
}
+
+ @Test
+ public void testH5DArray_string_buffer() throws Throwable
+ {
+ String dset_str_name = "ArrayStringdata";
+ long dset_str_id = HDF5Constants.H5I_INVALID_HID;
+ long dtype_str_id = HDF5Constants.H5I_INVALID_HID;
+ long dspace_id = HDF5Constants.H5I_INVALID_HID;
+ long[] strdims = {4};
+ long[] dims = {6};
+ long lsize = 1;
+
+ String[] str_data0 = {"Parting", "is such", "sweet", "sorrow."};
+ String[] str_data1 = {"Testing", "one", "two", "three."};
+ String[] str_data2 = {"Dog,", "man's", "best", "friend."};
+ String[] str_data3 = {"Diamonds", "are", "a", "girls!"};
+ String[] str_data4 = {"S A", "T U R", "D A Y", "night"};
+ String[] str_data5 = {"That's", "all", "folks", "!!!"};
+
+ ArrayList[] arr_str_data = new ArrayList[6];
+ arr_str_data[0] = new ArrayList<String>(Arrays.asList(str_data0));
+ arr_str_data[1] = new ArrayList<String>(Arrays.asList(str_data1));
+ arr_str_data[2] = new ArrayList<String>(Arrays.asList(str_data2));
+ arr_str_data[3] = new ArrayList<String>(Arrays.asList(str_data3));
+ arr_str_data[4] = new ArrayList<String>(Arrays.asList(str_data4));
+ arr_str_data[5] = new ArrayList<String>(Arrays.asList(str_data5));
+
+ try {
+ H5dtid = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5DArray_string_buffer.H5.H5Tcopy: " + err);
+ }
+ assertTrue("testH5DArray_string_buffer.H5Tcopy: ", H5dtid >= 0);
+ try {
+ H5.H5Tset_size(H5dtid, HDF5Constants.H5T_VARIABLE);
+ assertTrue("testH5DArray_string_buffer.H5Tis_variable_str", H5.H5Tis_variable_str(H5dtid));
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5DArray_string_buffer.H5Tset_size: " + err);
+ }
+ try {
+ dtype_str_id = H5.H5Tarray_create(H5dtid, 1, strdims);
+ assertTrue("testH5DArray_string_buffer.H5Tarray_create: ", dtype_str_id >= 0);
+ }
+ catch (Exception err) {
+ if (dtype_str_id > 0)
+ try {
+ H5.H5Tclose(dtype_str_id);
+ }
+ catch (Exception ex) {
+ }
+ err.printStackTrace();
+ fail("testH5DArray_string_buffer: " + err);
+ }
+
+ try {
+ dspace_id = H5.H5Screate_simple(1, dims, null);
+ assertTrue(dspace_id > 0);
+ dset_str_id =
+ H5.H5Dcreate(H5fid, dset_str_name, dtype_str_id, dspace_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5DArray_string_buffer: ", dset_str_id >= 0);
+
+ H5.H5DwriteVL(dset_str_id, dtype_str_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, arr_str_data);
+ }
+ catch (Exception err) {
+ if (dset_str_id > 0)
+ try {
+ H5.H5Dclose(dset_str_id);
+ }
+ catch (Exception ex) {
+ }
+ if (dtype_str_id > 0)
+ try {
+ H5.H5Tclose(dtype_str_id);
+ }
+ catch (Exception ex) {
+ }
+ err.printStackTrace();
+ fail("testH5DArray_string_buffer: " + 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];
+
+ ArrayList[] arr_readbuf = new ArrayList[6];
+ for (int j = 0; j < lsize; j++)
+ arr_readbuf[j] = new ArrayList<String>();
+
+ try {
+ H5.H5DreadVL(dset_str_id, dtype_str_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, arr_readbuf);
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ finally {
+ if (dset_str_id > 0)
+ try {
+ H5.H5Dclose(dset_str_id);
+ }
+ catch (Exception ex) {
+ }
+ if (dtype_str_id > 0)
+ try {
+ H5.H5Tclose(dtype_str_id);
+ }
+ catch (Exception ex) {
+ }
+ }
+ assertTrue("testH5DArray_string_buffer:" + arr_readbuf[0].get(0),
+ arr_str_data[0].get(0).equals(arr_readbuf[0].get(0)));
+ assertTrue("testH5DArray_string_buffer:" + arr_readbuf[1].get(0),
+ arr_str_data[1].get(0).equals(arr_readbuf[1].get(0)));
+ assertTrue("testH5DArray_string_buffer:" + arr_readbuf[2].get(0),
+ arr_str_data[2].get(0).equals(arr_readbuf[2].get(0)));
+ assertTrue("testH5DArray_string_buffer:" + arr_readbuf[3].get(0),
+ arr_str_data[3].get(0).equals(arr_readbuf[3].get(0)));
+ }
+
+ @Test
+ public void testH5DArrayenum_rw()
+ {
+ String dset_enum_name = "ArrayEnumdata";
+ long dset_enum_id = HDF5Constants.H5I_INVALID_HID;
+ long dtype_enum_id = HDF5Constants.H5I_INVALID_HID;
+ long dtype_arr_enum_id = HDF5Constants.H5I_INVALID_HID;
+ long dspace_id = HDF5Constants.H5I_INVALID_HID;
+ long[] dims = {4};
+ long lsize = 1;
+ String enum_type = "Enum_type";
+ byte[] enum_val = new byte[1];
+ String enum_name = null;
+
+ // Create a enumerate datatype
+ try {
+ dtype_enum_id = H5.H5Tcreate(HDF5Constants.H5T_ENUM, (long)1);
+ assertTrue("testH5DArrayenum_wr.H5Tarray_create: ", dtype_enum_id >= 0);
+ }
+ catch (Throwable err) {
+ if (dtype_enum_id > 0)
+ try {
+ H5.H5Tclose(dtype_enum_id);
+ }
+ catch (Exception ex) {
+ }
+ err.printStackTrace();
+ fail("testH5DArrayenum_rw:H5Tcreate " + err);
+ }
+
+ try {
+ enum_val[0] = 10;
+ H5.H5Tenum_insert(dtype_enum_id, "RED", enum_val);
+ enum_val[0] = 11;
+ H5.H5Tenum_insert(dtype_enum_id, "GREEN", enum_val);
+ enum_val[0] = 12;
+ H5.H5Tenum_insert(dtype_enum_id, "BLUE", enum_val);
+ enum_val[0] = 13;
+ H5.H5Tenum_insert(dtype_enum_id, "ORANGE", enum_val);
+ enum_val[0] = 14;
+ H5.H5Tenum_insert(dtype_enum_id, "YELLOW", enum_val);
+
+ // Query member number and member index by member name, for enumeration type.
+ assertTrue("Can't get member number", H5.H5Tget_nmembers(dtype_enum_id) == 5);
+ assertTrue("Can't get correct index number",
+ H5.H5Tget_member_index(dtype_enum_id, "ORANGE") == 3);
+
+ // Commit enumeration datatype and close it */
+ H5.H5Tcommit(H5fid, enum_type, dtype_enum_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+
+ H5.H5Tclose(dtype_enum_id);
+
+ // Open the dataytpe for query
+ dtype_enum_id = H5.H5Topen(H5fid, enum_type, HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5DArrayenum_rw:H5Tcreate", dtype_enum_id >= 0);
+
+ // Query member number and member index by member name, for enumeration type
+ assertTrue("Can't get member number", H5.H5Tget_nmembers(dtype_enum_id) == 5);
+ assertTrue("Can't get correct index number",
+ H5.H5Tget_member_index(dtype_enum_id, "ORANGE") == 3);
+
+ // Query member value by member name, for enumeration type
+ H5.H5Tenum_valueof(dtype_enum_id, "ORANGE", enum_val);
+ assertTrue("Incorrect value for enum member", enum_val[0] == 13);
+
+ // Query member value by member index, for enumeration type
+ H5.H5Tget_member_value(dtype_enum_id, 2, enum_val);
+ assertTrue("Incorrect value for enum member", enum_val[0] == 12);
+
+ // Query member name by member value, for enumeration type
+ enum_val[0] = 14;
+ enum_name = H5.H5Tenum_nameof(dtype_enum_id, enum_val, 16);
+ assertTrue("Incorrect name for enum member", enum_name.compareTo("YELLOW") == 0);
+
+ ArrayList[] arr_enum_data = new ArrayList[4];
+ try {
+ // Write Integer data
+ arr_enum_data[0] = new ArrayList<Integer>(Arrays.asList(10, 11, 12, 13));
+ arr_enum_data[1] = new ArrayList<Integer>(Arrays.asList(11, 12, 13, 14));
+ arr_enum_data[2] = new ArrayList<Integer>(Arrays.asList(12, 13, 14, 10));
+ arr_enum_data[3] = new ArrayList<Integer>(Arrays.asList(13, 14, 10, 11));
+ Class dataClass = arr_enum_data.getClass();
+ assertTrue("testH5DArrayenum_wr.getClass: " + dataClass, dataClass.isArray());
+
+ try {
+ dtype_arr_enum_id = H5.H5Tarray_create(HDF5Constants.H5T_STD_U32LE, 1, dims);
+ assertTrue("testH5DArrayenum_wr.H5Tarray_create: ", dtype_arr_enum_id >= 0);
+ }
+ catch (Exception err) {
+ if (dtype_arr_enum_id > 0)
+ try {
+ H5.H5Tclose(dtype_arr_enum_id);
+ }
+ catch (Exception ex) {
+ }
+ err.printStackTrace();
+ fail("H5.testH5DArrayenum_wr: " + err);
+ }
+
+ dspace_id = H5.H5Screate_simple(1, dims, null);
+ assertTrue(dspace_id > 0);
+ dset_enum_id = H5.H5Dcreate(H5fid, dset_enum_name, dtype_arr_enum_id, dspace_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5DVLwr: ", dset_enum_id >= 0);
+
+ H5.H5DwriteVL(dset_enum_id, dtype_arr_enum_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, arr_enum_data);
+ }
+ catch (Throwable err) {
+ if (dset_enum_id > 0)
+ try {
+ H5.H5Dclose(dset_enum_id);
+ }
+ catch (Exception ex) {
+ }
+ if (dtype_enum_id > 0)
+ try {
+ H5.H5Tclose(dtype_enum_id);
+ }
+ catch (Exception ex) {
+ }
+ if (dtype_arr_enum_id > 0)
+ try {
+ H5.H5Tclose(dtype_arr_enum_id);
+ }
+ catch (Exception ex) {
+ }
+ err.printStackTrace();
+ fail("testH5DArrayenum_rw:query " + 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_enum_id, dtype_arr_enum_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, arr_readbuf);
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ assertTrue("testH5DVLArrayenum_wr:" + arr_readbuf[0].get(0),
+ arr_enum_data[0].get(0).equals(arr_readbuf[0].get(0)));
+ assertTrue("testH5DVLArrayenum_wr:" + arr_readbuf[1].get(0),
+ arr_enum_data[1].get(0).equals(arr_readbuf[1].get(0)));
+ assertTrue("testH5DVLArrayenum_wr:" + arr_readbuf[2].get(0),
+ arr_enum_data[2].get(0).equals(arr_readbuf[2].get(0)));
+ assertTrue("testH5DVLArrayenum_wr:" + arr_readbuf[3].get(0),
+ arr_enum_data[3].get(0).equals(arr_readbuf[3].get(0)));
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.testH5DArrayenum_wr: " + err);
+ }
+ finally {
+ if (dset_enum_id > 0)
+ try {
+ H5.H5Dclose(dset_enum_id);
+ }
+ catch (Exception ex) {
+ }
+ if (dtype_enum_id > 0)
+ try {
+ H5.H5Tclose(dtype_enum_id);
+ }
+ catch (Exception ex) {
+ }
+ if (dtype_arr_enum_id > 0)
+ try {
+ H5.H5Tclose(dtype_arr_enum_id);
+ }
+ catch (Exception ex) {
+ }
+ }
+ }
}
diff --git a/java/test/testfiles/JUnit-TestH5A.txt b/java/test/testfiles/JUnit-TestH5A.txt
index 49e5c97..f31c86c 100644
--- a/java/test/testfiles/JUnit-TestH5A.txt
+++ b/java/test/testfiles/JUnit-TestH5A.txt
@@ -29,9 +29,10 @@ JUnit version 4.11
.testH5Adelete_by_idx_null
.testH5Adelete_by_idx_invalidobject
.testH5Awrite_readVL
+.testH5AArray_string_buffer
.testH5Aget_info1
Time: XXXX
-OK (31 tests)
+OK (32 tests)
diff --git a/java/test/testfiles/JUnit-TestH5D.txt b/java/test/testfiles/JUnit-TestH5D.txt
index 19abd80..4c30621 100644
--- a/java/test/testfiles/JUnit-TestH5D.txt
+++ b/java/test/testfiles/JUnit-TestH5D.txt
@@ -1,4 +1,5 @@
JUnit version 4.11
+.testH5DArrayenum_rw
.testH5DVLwrVL
.testH5Dget_storage_size
.testH5DArraywr
@@ -14,8 +15,8 @@ JUnit version 4.11
.testH5Dget_storage_size_empty
.testH5Diterate
.testH5Dget_access_plist
-.testH5Dvlen_get_buf_size
.testH5Dget_space_closed
+.testH5DArray_string_buffer
.testH5Dget_space_status
.testH5Dvlen_write_read
.testH5Dget_space
@@ -23,5 +24,5 @@ JUnit version 4.11
Time: XXXX
-OK (21 tests)
+OK (22 tests)