public class HdfIOFactory extends java.lang.Object implements IHdfIOFactory
This class provides a base for implementing IHdfIOFactory
and
includes many helpful methods for writing and reading HDF5 attributes,
datasets, groups, and more.
Sub-classes must override the following methods (no calls to the super method necessary):
Note that this class cannot be abstract because it references an OSGi service so that sub-classes have easy access to theIHdfIORegistry
implementation.
Constructor and Description |
---|
HdfIOFactory() |
Modifier and Type | Method and Description |
---|---|
void |
closeGroup(int groupId)
Closes an HDF5 Group.
|
int |
createGroup(int parentId,
java.lang.String name)
Creates and opens an HDF5 Group.
|
java.lang.Object[] |
getBuffer(int type)
Gets a buffer used for writing or reading an HDF5 attribute.
|
java.lang.Object |
getBuffer(int type,
long[] dims)
Gets a buffer used for writing or reading HDF5 datasets.
|
java.util.List<java.lang.String> |
getChildNames(int parentId,
int objectType)
Gets a List of all child Objects of an HDF5 Group with the specified ID
and type.
|
static IHdfIORegistry |
getHdfIORegistry()
Gets the
IHdfIORegistry implementation that is running as an OSGi
Declarative Service. |
java.util.List<java.lang.Class<?>> |
getSupportedClasses()
Sub-classes must override this method.
|
java.lang.String |
getTag(java.lang.Class<?> supportedClass)
Sub-classes must override this method.
|
int |
openGroup(int parentId,
java.lang.String name)
Opens an HDF5 Group.
|
java.lang.Object |
read(int groupId,
java.lang.String tag)
Sub-classes must override this method.
|
java.lang.Object |
readAttribute(int objectId,
java.lang.String name,
int type)
Reads an Attribute for an HDF5 Object, which is typically a Group.
|
java.lang.Object |
readDataset(int groupId,
java.lang.String name,
int type)
Reads a dataset without requiring advance knowledge of its entire
structure.
|
void |
readICEObjectInfo(ICEObject object,
int objectId)
Reads the ICEObject information (name, description, ID) from an HDF5
Group or Object into an ICEObject.
|
java.util.List<java.lang.Object> |
readObjects(java.net.URI uri)
Reads all objects from the file specified by the URI.
|
java.lang.String |
readStringAttribute(int objectId,
java.lang.String name)
Reads a String Attribute from an HDF5 Object, which is typically a Group.
|
java.lang.String |
readTag(int objectId)
Reads the value of a tag from the specified HDF5 Group.
|
static void |
setHdfIORegistry(IHdfIORegistry registry)
Sets the
IHdfIORegistry implementation that is running as an OSGi
Declarative Service. |
void |
throwException(java.lang.String message,
int status)
This utility method throws an HDF5LibraryException with a custom message.
|
static void |
unsetHdfIORegistry(IHdfIORegistry registry)
Unsets the
IHdfIORegistry implementation. |
void |
write(int parentGroupId,
java.lang.Object object)
When writing an object to an HDF5 file, we must create a tag Attribute.
|
void |
writeAttribute(int objectId,
java.lang.String name,
int type,
java.lang.Object value)
Writes an Attribute for an HDF5 Object, which is typically a Group.
|
void |
writeDataset(int objectId,
java.lang.String name,
int rank,
long[] dims,
int type,
java.lang.Object buffer)
This method writes an HDF5 Dataset containing the data that is stored in
a buffer.
|
void |
writeICEObjectInfo(ICEObject object,
int objectId)
Writes an ICEObject's name, description, and ID as Attributes for an HDF5
Object.
|
void |
writeObjectData(int groupId,
java.lang.Object object)
Sub-classes must override this method.
|
void |
writeObjects(java.net.URI uri,
java.util.List<java.lang.Object> objects)
Writes several objectss to the file specified by the URI.
|
void |
writeStringAttribute(int objectId,
java.lang.String name,
java.lang.String value)
Writes a String as an Attribute for an HDF5 Object, which is typically a
Group.
|
void |
writeTag(java.lang.String tag,
int objectId)
Writes the tag value for the specified HDF5 Group.
|
public java.util.List<java.lang.Class<?>> getSupportedClasses()
getSupportedClasses
in interface IHdfIOFactory
public java.lang.String getTag(java.lang.Class<?> supportedClass)
getTag
in interface IHdfIOFactory
supportedClass
- The supported class.public java.lang.Object read(int groupId, java.lang.String tag) throws java.lang.NullPointerException, ncsa.hdf.hdf5lib.exceptions.HDF5Exception, ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
read
in interface IHdfIOFactory
groupId
- The HDF5 file ID for the group containing the object.tag
- The tag Attribute for the group. This specifies the type of
object to be read from the file.java.lang.NullPointerException
ncsa.hdf.hdf5lib.exceptions.HDF5Exception
ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
public void writeObjectData(int groupId, java.lang.Object object) throws java.lang.NullPointerException, ncsa.hdf.hdf5lib.exceptions.HDF5Exception, ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
groupId
- The group for the object.object
- The object whose information is being written to the group.java.lang.NullPointerException
ncsa.hdf.hdf5lib.exceptions.HDF5Exception
ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
public static void setHdfIORegistry(IHdfIORegistry registry)
IHdfIORegistry
implementation that is running as an OSGi
Declarative Service.public static void unsetHdfIORegistry(IHdfIORegistry registry)
IHdfIORegistry
implementation. This happens only when
the bundle has shut down.public static IHdfIORegistry getHdfIORegistry()
IHdfIORegistry
implementation that is running as an OSGi
Declarative Service.public void write(int parentGroupId, java.lang.Object object) throws java.lang.NullPointerException, ncsa.hdf.hdf5lib.exceptions.HDF5Exception, ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
writeObjectData(int, Object)
.write
in interface IHdfIOFactory
parentGroupId
- The HDF5 file ID for the parent group containing the object.object
- An object to write to HDF5. If the object type is not
supported by the handler, nothing is written.java.lang.NullPointerException
ncsa.hdf.hdf5lib.exceptions.HDF5Exception
ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
public final void writeObjects(java.net.URI uri, java.util.List<java.lang.Object> objects)
uri
- The URI of the file that will hold the objects.objects
- The objects that will be written to the file.public final java.util.List<java.lang.Object> readObjects(java.net.URI uri)
uri
- The URI of the file that should contain readable objects.public final void throwException(java.lang.String message, int status) throws ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
message
- The message to append to the exception.status
- The integer flag that indicated a problem. This is usually a
negative number.ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
public final int openGroup(int parentId, java.lang.String name) throws ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException, java.lang.NullPointerException
parentId
- The ID of the parent's Group, which should be open itself.name
- The name of the Group to open.ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
java.lang.NullPointerException
public final int createGroup(int parentId, java.lang.String name) throws ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException, java.lang.NullPointerException
parentId
- The ID of the parent's Group, which should be open itself.name
- The name of the Group to open.ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
java.lang.NullPointerException
public final void closeGroup(int groupId) throws ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
groupId
- The ID of the Group to close.ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
public final java.util.List<java.lang.String> getChildNames(int parentId, int objectType) throws ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
parentId
- The ID of the parent Group.objectType
- The type of object we are looking for, e.g., H5O_TYPE_GROUP or
H5O_TYPE_DATASET.ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
public final void writeAttribute(int objectId, java.lang.String name, int type, java.lang.Object value) throws java.lang.NullPointerException, ncsa.hdf.hdf5lib.exceptions.HDF5Exception
objectId
- The ID for the Object, which should be open, that will get the
Attribute.name
- The name of the Attribute.type
- The HDF5 datatype of the Attribute. Currently supported are
H5T_NATIVE_INT and H5T_NATIVE_DOUBLE.value
- The value of the Attribute being written.java.lang.NullPointerException
ncsa.hdf.hdf5lib.exceptions.HDF5Exception
public final java.lang.Object readAttribute(int objectId, java.lang.String name, int type) throws java.lang.NullPointerException, ncsa.hdf.hdf5lib.exceptions.HDF5Exception
objectId
- The ID for the Object, which should be open, that has the
Attribute.name
- The name of the Attribute.type
- The HDF5 datatype of the Attribute. Currently supported are
H5T_NATIVE_INT and H5T_NATIVE_DOUBLE.java.lang.NullPointerException
ncsa.hdf.hdf5lib.exceptions.HDF5Exception
public final void writeStringAttribute(int objectId, java.lang.String name, java.lang.String value) throws java.lang.NullPointerException, ncsa.hdf.hdf5lib.exceptions.HDF5Exception
objectId
- The ID for the Object, which should be open, that will get the
Attribute.name
- The name of the Attribute.value
- The String value of the Attribute.java.lang.NullPointerException
ncsa.hdf.hdf5lib.exceptions.HDF5Exception
public final java.lang.String readStringAttribute(int objectId, java.lang.String name) throws java.lang.NullPointerException, ncsa.hdf.hdf5lib.exceptions.HDF5Exception
objectId
- The ID for the Object, which should be open, that has the
Attribute.name
- The name of the Attribute.java.lang.NullPointerException
ncsa.hdf.hdf5lib.exceptions.HDF5Exception
public final void writeDataset(int objectId, java.lang.String name, int rank, long[] dims, int type, java.lang.Object buffer) throws java.lang.NullPointerException, ncsa.hdf.hdf5lib.exceptions.HDF5Exception
objectId
- The ID for the Object, which should be open, that will get the
Dataset.name
- The name of the Dataset.rank
- The number of dimensions in the data.dims
- An array containing the sizes of each dimension in the data.type
- The HDF5 datatype of the data in the Dataset, e.g.,
H5T_NATIVE_INT or H5T_NATIVE_DOUBLE. This may also be an ID
for an opened Datatype, e.g., an array of Strings (byte
arrays).buffer
- The buffer that contains the data to write. This needs to be
an array, e.g., a double[n] or int[n].java.lang.NullPointerException
ncsa.hdf.hdf5lib.exceptions.HDF5Exception
public java.lang.Object readDataset(int groupId, java.lang.String name, int type) throws java.lang.NullPointerException, ncsa.hdf.hdf5lib.exceptions.HDF5Exception
groupId
- The ID of the Object, which should be open, that contains the
dataset.name
- The name of the dataset.type
- The HDF5 datatype of the data in the dataset, e.g.,
H5T_NATIVE_INT or H5T_NATIVE_DOUBLE. This may also be an ID
for an opened datatype, e.g., an array of Strings (byte
arrays).java.lang.NullPointerException
ncsa.hdf.hdf5lib.exceptions.HDF5Exception
public final void writeICEObjectInfo(ICEObject object, int objectId) throws java.lang.NullPointerException, ncsa.hdf.hdf5lib.exceptions.HDF5Exception
object
- The ICEObject whose info should be written in HDF5.objectId
- The ID of the HDF5 Object receiving the ICEObject Attributes.java.lang.NullPointerException
ncsa.hdf.hdf5lib.exceptions.HDF5Exception
public final void readICEObjectInfo(ICEObject object, int objectId) throws java.lang.NullPointerException, ncsa.hdf.hdf5lib.exceptions.HDF5Exception
object
- The ICEObject that should have its information set.objectId
- The ID of the HDF5 Group or Object that contains the
ICEObject's information.java.lang.NullPointerException
ncsa.hdf.hdf5lib.exceptions.HDF5Exception
public final void writeTag(java.lang.String tag, int objectId) throws java.lang.NullPointerException, ncsa.hdf.hdf5lib.exceptions.HDF5Exception
tag
- The tag string.objectId
- The HDF5 Group that will have the specified tag.java.lang.NullPointerException
ncsa.hdf.hdf5lib.exceptions.HDF5Exception
public java.lang.String readTag(int objectId) throws java.lang.NullPointerException, ncsa.hdf.hdf5lib.exceptions.HDF5Exception
objectId
- The HDF5 Group that should have a tag Attribute.java.lang.NullPointerException
ncsa.hdf.hdf5lib.exceptions.HDF5Exception
public final java.lang.Object[] getBuffer(int type) throws ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
type
- The data type, e.g. HDF5Constants.H5T_NATIVE_DOUBLE
or
HDF5Constants.H5T_NATIVE_INT
.ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
public final java.lang.Object getBuffer(int type, long[] dims) throws ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException
type
- The data type, e.g. HDF5Constants.H5T_NATIVE_DOUBLE
or
HDF5Constants.H5T_NATIVE_INT
.dims
- The sizes of each dimension of the data.ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException