Cleanest way to determine if a dataset exists using Java API


#1

What’s the cleanest way to determine if a dataset existing using the Java API. I’m currently using the following; however, I prefer not to use exception handling this way.

private boolean exists(long fileId, String dataset)
{
long datasetId = -1L;

try
{
	datasetId = H5.H5Dopen(fileId, dataset, HDF5Constants.H5P_DEFAULT);
}
catch (HDF5LibraryException | NullPointerException ex)
{
	// do nothing
}
finally
{
	try
	{
		H5.H5Dclose(datasetId);
	}
	catch (HDF5LibraryException ex)
	{
		// do nothing
	}
}

return datasetId != -1L;

}


#2

In C, I think I would use H5Lexists(). Does Java interface have similar?


#3

Hi Steven,
I’m not certain if the Java API has this routine, but the C interface has H5Lexists().

	Quincey

#4

Yes, the Java interface has this wrapped and returns a boolean.