Class Hdf5Writer

  • All Implemented Interfaces:
    AutoCloseable

    public class Hdf5Writer
    extends Object
    implements AutoCloseable
    This is an early template of what we need in terms of static HDF5 writer. Should be refactored and put in a core i/o class
    Author:
    yngvelevinsen
    • Constructor Detail

      • Hdf5Writer

        public Hdf5Writer()
        Create a new writer object. Need to call setSource() after to open the HDF5 file for writing.
    • Method Detail

      • close

        public void close()
        Make sure HDF5 file is closed before instance is destroyed (unsure if this is necessary tbh)
        Specified by:
        close in interface AutoCloseable
      • closeSourceFile

        public void closeSourceFile()
        Closes the HDF file access. Should also flush any remaining output.
      • setSource

        public void setSource​(String filePath)
                       throws Exception
        Set the path to the HDF file and open it
        Parameters:
        filePath - Path to HDF file
        Throws:
        Exception - If there was a problem opening the file
      • writeHDF5Attribute

        public void writeHDF5Attribute​(String path,
                                       String attributeName,
                                       String attributeContent)
                                throws Exception
        Write a string attribute to a H5Object in the file
        Parameters:
        path - Path to H5Object that should have the attribute
        attributeName - Name of attribute
        attributeContent - Content of attribute
        Throws:
        Exception - If there is a problem creating the attribute
      • getOrCreateGroup

        public hdf.object.h5.H5Group getOrCreateGroup​(hdf.object.h5.H5File h5File,
                                                      String path)
                                               throws Exception
        If the name already exist in group, return it cast as a H5Group, otherwise create it and return the object.
        Parameters:
        h5File - The name of the child group object
        path - The name of the parent group
        Returns:
        The child group
        Throws:
        Exception - If there was a problem creating a group
      • h5GetAllGroups

        public ArrayList<String> h5GetAllGroups​(String groupPath)
                                         throws Exception
        Returns all groups one level below the group path given
        Parameters:
        groupPath - Path to group (e.g "/" to get top level)
        Returns:
        list of all groups one level below
        Throws:
        Exception - If there was a problem creating a group
      • h5LibsWorks

        public static boolean h5LibsWorks()
        Test HDF5 writing, return true if it works well
        Returns:
        True if you are able to write HDF5 files