Package hdf.object

Class FileFormat

  • All Implemented Interfaces:
    Serializable, Comparable<File>

    public abstract class FileFormat
    extends File
    FileFormat defines general interfaces for working with files whose data is organized according to a supported format.

    FileFormat is a pluggable component. New implementing classes of FileFormat can be added to the list of supported file formats. Current implementing classes include H5File and H4File. By default, H5File and H4File are added to the list of supported file formats maintained by the static FileFormat instance.

                                        FileFormat
                           _________________|_________________
                           |                |                |
                         H5File          H4File           Other...
     

    A FileFormat instance may exist without being associated with a given file. A FileFormat instance may be associated with a file that is not open for access. Most typically, a FileFormat instance is used to open the associated file and perform operations such as retrieval and manipulation (if the file access is read-write) of the file structure and objects.

    Version:
    2.4 9/4/2007
    Author:
    Peter X. Cao
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int CREATE
      File access flag for creating/truncating with read-write permission.
      protected long fid
      File identifier.
      static int FILE_CREATE_DELETE
      Flag for creating/truncating a file.
      static int FILE_CREATE_EARLY_LIB
      Flag to indicate if the earliest version of library is used when creating a new file.
      static int FILE_CREATE_OPEN
      Flag for creating/opening a file.
      static String FILE_OBJ_SEP
      A separator that separates file name and object name.
      static String FILE_TYPE_HDF4
      Key for HDF4 file format.
      static String FILE_TYPE_HDF5
      Key for HDF5 file format.
      static String FILE_TYPE_NC3
      Key for NetCDF file format.
      protected String fullFileName
      The absolute pathname (path+name) of the file.
      protected boolean isReadOnly
      Flag indicating if the file access is read-only.
      static int OPEN_NEW
      File first time access flag for open file.
      static int READ
      File access flag for read-only permission.
      static int WRITE
      File access flag for read/write permission.
      • Fields inherited from class java.io.File

        pathSeparator, pathSeparatorChar, separator, separatorChar
    • Constructor Summary

      Constructors 
      Constructor Description
      FileFormat​(String filename)
      Creates a new FileFormat instance with the given filename.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void addFileExtension​(String extension)
      Adds file extension(s) to the list of file extensions for supported file formats.
      static void addFileFormat​(String key, FileFormat fileformat)
      Adds a FileFormat with specified key to the list of supported formats.
      abstract void close()
      Closes file associated with this instance.
      HObject copy​(HObject srcObj, Group dstGroup)
      Deprecated.
      As of 2.4, replaced by copy(HObject, Group, String)
      abstract HObject copy​(HObject srcObj, Group dstGroup, String dstName)
      Copies the source object to a new destination.
      FileFormat create​(String fileName)
      Deprecated.
      As of 2.4, replaced by createFile(String, int)
      Dataset createCompoundDS​(String name, Group pgroup, long[] dims, long[] maxdims, long[] chunks, int gzip, String[] memberNames, Datatype[] memberDatatypes, int[] memberSizes, Object data)
      Creates a new compound dataset in a file with/without chunking and compression.
      Dataset createCompoundDS​(String name, Group pgroup, long[] dims, String[] memberNames, Datatype[] memberDatatypes, int[] memberSizes, Object data)
      abstract Datatype createDatatype​(int tclass, int tsize, int torder, int tsign)
      Creates a new datatype in memory.
      Datatype createDatatype​(int tclass, int tsize, int torder, int tsign, Datatype tbase)
      Creates a new datatype in memory.
      Datatype createDatatype​(int tclass, int tsize, int torder, int tsign, Datatype tbase, String name)
      Creates a named datatype in a file.
      abstract Datatype createDatatype​(int tclass, int tsize, int torder, int tsign, String name)
      Creates a named datatype in a file.
      FileFormat createFile​(String filename, int createFlag)
      Creates a file with the specified name and returns a new FileFormat implementation instance associated with the file.
      long createGcpl​(int creationorder, int maxcompact, int mindense)
      Creates the group creation property list identifier, gcpl.
      abstract Group createGroup​(String name, Group parentGroup)
      Creates a new group with specified name in existing group.
      Group createGroup​(String name, Group pgroup, long... gplist)
      Creates a new group with specified name in existing group.
      abstract Dataset createImage​(String name, Group pgroup, Datatype type, long[] dims, long[] maxdims, long[] chunks, int gzip, int ncomp, int interlace, Object data)
      Creates a new image in a file.
      abstract FileFormat createInstance​(String filename, int access)
      Creates a FileFormat implementation instance with specified filename and access.
      HObject createLink​(Group parentGroup, String name, HObject currentObj, int type)
      Creates a soft, hard or external link to an existing object in the open file.
      HObject createLink​(Group linkGroup, String name, Object currentObj)
      Creates a link to an existing object in the open file.
      HObject createLink​(Group parentGroup, String name, String currentObj, int type)
      Creates a soft or external link to an object in a file that does not exist at the time the link is created.
      Dataset createScalarDS​(String name, Group pgroup, Datatype type, long[] dims, long[] maxdims, long[] chunks, int gzip, Object data)  
      abstract Dataset createScalarDS​(String name, Group pgroup, Datatype type, long[] dims, long[] maxdims, long[] chunks, int gzip, Object fillValue, Object data)
      Creates a new dataset in a file with/without chunking/compression.
      abstract void delete​(HObject obj)
      Deletes an object from a file.
      void exportDataset​(String file_export_name, String file_name, String object_path, int binary_order)
      Export dataset.
      static HObject findObject​(FileFormat file, long[] oid)
      Finds an object by its object ID
      static HObject findObject​(FileFormat file, String path)
      Finds an object by the full path of the object (path+name)
      abstract HObject get​(String path)
      Gets the HObject with the specified path from the file.
      long getFID()
      Returns file identifier of open file associated with this instance.
      static String getFileExtensions()
      Returns a list of file extensions for all supported file formats.
      static FileFormat getFileFormat​(String key)
      Returns the FileFormat with specified key from the list of supported formats.
      static Enumeration getFileFormatKeys()
      Returns an Enumeration of keys for all supported formats.
      static FileFormat[] getFileFormats()
      Returns an array of supported FileFormat instances.
      String getFilePath()
      Returns the absolute path for the file.
      static HObject getHObject​(String fullPath)
      Deprecated.
      As of 2.4, replaced by get(String)
      static HObject getHObject​(String filename, String path)
      Deprecated.
      As of 2.4, replaced by get(String)
      int getIndexOrder​(String strorder)  
      static int getIndexOrderValue​(String strorder)  
      int getIndexType​(String strtype)  
      static int getIndexTypeValue​(String strtype)  
      static FileFormat getInstance​(String filename)
      Creates a FileFormat instance for the specified file.
      int[] getLibBounds()
      Gets the bounds of library versions
      String getLibBoundsDescription()  
      abstract String getLibversion()
      Returns the version of the library for the implementing FileFormat class.
      int getMaxMembers()
      Returns the maximum number of objects that can be loaded into memory.
      int getNumberOfMembers()
      Returns the number of objects in memory.
      abstract HObject getRootObject()
      Returns the root object for the file associated with this instance.
      int getStartMembers()
      Returns the index of the starting object to be loaded into memory.
      boolean isReadOnly()
      Returns true if the file access is read-only.
      abstract boolean isThisType​(FileFormat fileFormat)
      Checks if the class implements the specified FileFormat.
      abstract boolean isThisType​(String filename)
      Checks if the implementing FileFormat class matches the format of the specified file.
      abstract long open()
      Opens file and returns a file identifier.
      long open​(int... indexList)
      Opens file and returns a file identifier.
      FileFormat open​(String pathname, int access)
      Deprecated.
      As of 2.4, replaced by createInstance(String, int) The replacement method has identical functionality and a more descriptive name.
      static FileFormat removeFileFormat​(String key)
      Removes a FileFormat from the list of supported formats.
      void renameAttribute​(HObject obj, String oldAttrName, String newAttrName)
      Renames an attribute.
      void setIndexOrder​(int indexOrder)  
      void setIndexType​(int indexType)  
      void setLibBounds​(String lowStr, String highStr)
      Sets the bounds of library versions.
      void setMaxMembers​(int n)
      Sets the maximum number of objects to be loaded into memory.
      void setNewLibBounds​(String lowStr, String highStr)
      Sets the bounds of new library versions.
      void setStartMembers​(int idx)
      Sets the starting index of objects to be loaded into memory.
      abstract void writeAttribute​(HObject obj, Attribute attr, boolean attrExisted)
      Attaches a given attribute to an object.
      • Methods inherited from class java.io.File

        canExecute, canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getFreeSpace, getName, getParent, getParentFile, getPath, getTotalSpace, getUsableSpace, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setExecutable, setExecutable, setLastModified, setReadable, setReadable, setReadOnly, setWritable, setWritable, toPath, toString, toURI, toURL
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • FileFormat

        public FileFormat​(String filename)
        Creates a new FileFormat instance with the given filename.

        The filename in this method call is equivalent to the pathname in the java.io.File class. The filename is converted into an abstract pathname by the File class.

        Typically this constructor is not called directly, but is called by a constructor of an implementing class. Applications most frequently use the createFile(), createInstance(), or getInstance() methods to generate a FileFormat instance with an associated filename.

        The file is not opened by this call. The read-only flag is set to false by this call.

        Parameters:
        filename - The filename; a pathname string.
        Throws:
        NullPointerException - If the filename argument is null.
        See Also:
        File(String), createFile(String, int), createInstance(String, int), getInstance(String)
    • Method Detail

      • addFileFormat

        public static final void addFileFormat​(String key,
                                               FileFormat fileformat)
        Adds a FileFormat with specified key to the list of supported formats.

        This method allows a new FileFormat, tagged with an identifying key, to be added dynamically to the list of supported File Formats. Using it, applications can add new File Formats at runtime.

        For example, to add a new File Format with the key "xyz" that is implemented by the class xyzFile in the package companyC.files, an application would make the following calls:

            Class fileClass = Class.forName( "companyC.files.xyzFile" );
            FileFormat ff = (FileFormat) fileClass.newInstance();
            if ( ff != null ) {
               ff.addFileFormat ("xyz", ff )
            }
         

        If either key or fileformat are null, or if key is already in use, the method returns without updating the list of supported File Formats.

        Parameters:
        key - A string that identifies the FileFormat.
        fileformat - An instance of the FileFormat to be added.
        See Also:
        getFileFormat(String), getFileFormatKeys(), getFileFormats(), removeFileFormat(String)
      • getFileFormat

        public static final FileFormat getFileFormat​(String key)
        Returns the FileFormat with specified key from the list of supported formats.

        This method returns a FileFormat instance, as identified by an identifying key, from the list of supported File Formats.

        If the specified key is in the list of supported formats, the instance of the associated FileFormat object is returned. If the specified key is not in the list of supported formats, null is returned.

        Parameters:
        key - A string that identifies the FileFormat.
        Returns:
        The FileFormat that matches the given key, or null if the key is not found in the list of supported File Formats.
        See Also:
        addFileFormat(String,FileFormat), getFileFormatKeys(), getFileFormats(), removeFileFormat(String)
      • removeFileFormat

        public static final FileFormat removeFileFormat​(String key)
        Removes a FileFormat from the list of supported formats.

        This method removes a FileFormat, as identified by the specified key, from the list of supported File Formats.

        If the specified key is in the list of supported formats, the instance of the FileFormat object that is being removed from the list is returned. If the key is not in the list of supported formats, null is returned.

        Parameters:
        key - A string that identifies the FileFormat to be removed.
        Returns:
        The FileFormat that is removed, or null if the key is not found in the list of supported File Formats.
        See Also:
        addFileFormat(String,FileFormat), getFileFormat(String), getFileFormatKeys(), getFileFormats()
      • addFileExtension

        public static final void addFileExtension​(String extension)
        Adds file extension(s) to the list of file extensions for supported file formats.

        Multiple extensions can be included in the single parameter if they are separated by commas.

        The list of file extensions updated by this call is not linked with supported formats that implement FileFormat objects. The file extension list is maintained for the benefit of applications that may choose to recognize only those files with extensions that appear in the list of file extensions for supported file formats.

        By default, the file extensions list includes: "hdf, h4, hdf5, h5"

        Parameters:
        extension - The file extension(s) to add.
        See Also:
        addFileFormat(String,FileFormat), getFileExtensions()
      • getFileExtensions

        public static final String getFileExtensions()
        Returns a list of file extensions for all supported file formats.

        The extensions in the returned String are separates by commas: "hdf, h4, hdf5, h5"

        It is the responsibility of the application to update the file extension list using addFileExtension(String) when new FileFormat implementations are added.

        Returns:
        A list of file extensions for all supported file formats.
        See Also:
        addFileExtension(String)
      • getInstance

        public static final FileFormat getInstance​(String filename)
                                            throws Exception
        Creates a FileFormat instance for the specified file.

        This method checks the list of supported file formats to find one that matches the format of the specified file. If a match is found, the method returns an instance of the associated FileFormat object. If no match is found, null is returned.

        For example, if "test_hdf5.h5" is an HDF5 file, FileFormat.getInstance("test_hdf5.h5") will return an instance of H5File.

        The file is not opened as part of this call. Read/write file access is associated with the FileFormat instance if the matching file format supports read/write access. Some file formats only support read access.

        Parameters:
        filename - A valid file name, with a relative or absolute path.
        Returns:
        An instance of the matched FileFormat; null if no match.
        Throws:
        IllegalArgumentException - If the filename argument is null or does not specify an existing file.
        Exception - If there are problems creating the new instance.
        See Also:
        createFile(String, int), createInstance(String, int), getFileFormats()
      • getLibversion

        public abstract String getLibversion()
        Returns the version of the library for the implementing FileFormat class.

        The implementing FileFormat classes have freedom in how they obtain or generate the version number that is returned by this method. The H5File and H4File implementations query the underlying HDF libraries and return the reported version numbers. Other implementing classes may generate the version string directly within the called method.

        Returns:
        The library version.
      • isThisType

        public abstract boolean isThisType​(FileFormat fileFormat)
        Checks if the class implements the specified FileFormat.

        The Java "instanceof" operation is unable to check if an object is an instance of a FileFormat that is loaded at runtime. This method provides the "instanceof" functionality, and works for implementing classes that are loaded at runtime.

        This method lets applications that only access the abstract object layer determine the format of a given instance of the abstract class.

        For example, HDFView uses the following code to determine if a file is an HDF5 file:

         FileFormat h5F = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
         HObject hObject = viewer.getTreeView().getCurrentObject();
         FileFormat thisF = hObject.getFileFormat();
         boolean isH5 = h5F.isThisType(thisF);
         
        Parameters:
        fileFormat - The FileFormat to be checked.
        Returns:
        True if this instance implements the specified FileFormat; otherwise returns false.
        See Also:
        isThisType(String)
      • isThisType

        public abstract boolean isThisType​(String filename)
        Checks if the implementing FileFormat class matches the format of the specified file.

        For example, if "test.h5" is an HDF5 file, the first call to isThisType() in the code fragment shown will return false, and the second call will return true.

         FileFormat ncF = FileFormat.getFileFormat(FileFormat.FILE_TYPE_NC3);
         FileFormat h4F = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF4);
         FileFormat h5F = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
         boolean isH4 = h4F.isThisType("test.h5"); // false
                                                                                                                                                                                           boolean isH5 = h5F.isThisType("test.h5"); // true
         
        Parameters:
        filename - The name of the file to be checked.
        Returns:
        True if the format of the file matches the format of this instance; otherwise returns false.
        See Also:
        isThisType(FileFormat)
      • createFile

        public FileFormat createFile​(String filename,
                                     int createFlag)
                              throws Exception
        Creates a file with the specified name and returns a new FileFormat implementation instance associated with the file.

        This method creates a file whose format is the same as that of the implementing class. An instance of the FileFormat implementing class is created and associated with the file. That instance is returned by the method.

        The filename in this method call is equivalent to the pathname in the java.io.File class. The filename is converted into an abstract pathname by the File class.

        A flag controls the behavior if the named file already exists. The flag values and corresponding behaviors are:

        • FILE_CREATE_DELETE: Create a new file or truncate an existing one.
        • FILE_CREATE_OPEN: Create a new file or open an existing one.

        If the flag is FILE_CREATE_DELETE, the method will create a new file or truncate an existing file. If the flag is FILE_CREATE_OPEN and the file does not exist, the method will create a new file.

        This method does not open the file for access, nor does it confirm that the file can later be opened read/write. The file open is carried out by the open() call.

        Parameters:
        filename - The filename; a pathname string.
        createFlag - The creation flag, which determines behavior when the file already exists. Acceptable values are FILE_CREATE_DELETE and FILE_CREATE_OPEN.
        Returns:
        the FileFormat instance.
        Throws:
        NullPointerException - If the filename argument is null.
        UnsupportedOperationException - If the implementing class does not support the file creation operation.
        Exception - If the file cannot be created or if the creation flag has an unexpected value. The exceptions thrown vary depending on the implementing class.
        See Also:
        createInstance(String, int), getInstance(String), open()
      • createInstance

        public abstract FileFormat createInstance​(String filename,
                                                  int access)
                                           throws Exception
        Creates a FileFormat implementation instance with specified filename and access.

        This method creates an instance of the FileFormat implementing class and sets the filename and file access parameters.

        The filename in this method call is equivalent to the pathname in the java.io.File class. The filename is converted into an abstract pathname by the File class.

        The access parameter values and corresponding behaviors at file open:

        • READ: Read-only access. Fail if file doesn't exist.
        • WRITE: Read/Write access. Behavior if file doesn't exist or can't be opened for read/write access depends on the implementing class.
        • CREATE: Read/Write access. Create a new file or truncate an existing one. Behavior if file can't be created, or if it exists but can't be opened read/write depends on the implementing class.

        Some FileFormat implementing classes may only support READ access and will use READ regardless of the value specified in the call. Refer to the implementing class documentation for details.

        This method does not open the file for access, nor does it confirm that the file can later be opened read/write or created. The file open is carried out by the open() call.

        Example (without exception handling):

         // Request the implementing class of FileFormat: H5File
         FileFormat h5file = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
        
         // Create an instance of H5File object with read/write access
         H5File test1 = (H5File) h5file.createInstance("test_hdf5.h5",
                                                       FileFormat.WRITE);
        
         // Open the file and load the file structure; file id is returned.
         int fid = test1.open();
         
        Parameters:
        filename - The filename; a pathname string.
        access - The file access flag, which determines behavior when file is opened. Acceptable values are READ, WRITE, and CREATE.
        Returns:
        the FileFormat instance.
        Throws:
        NullPointerException - If the filename argument is null.
        Exception - If the instance cannot be created or if the access flag has an unexpected value. The exceptions thrown vary depending on the implementing class.
        See Also:
        createFile(String, int), getInstance(String), open()
      • getFilePath

        public final String getFilePath()
        Returns the absolute path for the file.

        For example, "/samples/hdf5_test.h5". If there is no file associated with this FileFormat instance, null is returned.

        Returns:
        The full path (file path + file name) of the associated file, or null if there is no associated file.
      • getFID

        public final long getFID()
        Returns file identifier of open file associated with this instance.
        Returns:
        The file identifer, or -1 if there is no file open.
      • isReadOnly

        public final boolean isReadOnly()
        Returns true if the file access is read-only.

        This method returns true if the file access is read-only. If the file access is read-write, or if there is no file associated with the FileFormat instance, false will be returned.

        Note that this method may return true even if the file is not open for access when the method is called. The file access is set by the createFile(), createInstance(), or getInstance() call, and the file is opened for access by the open() call.

        Returns:
        True if the file access is read-only, otherwise returns false.
        See Also:
        createFile(String, int), createInstance(String, int), getInstance(String), open()
      • setMaxMembers

        public final void setMaxMembers​(int n)
        Sets the maximum number of objects to be loaded into memory.

        Current Java applications, such as HDFView, cannot handle files with large numbers of objects due to JVM memory limitations. The maximum number limits the number of objects that will be loaded for a given FileFormat instance.

        The implementing FileFormat class has freedom in how it interprets the maximum number. H5File, for example, will load the maximum number of objects for each group in the file.

        Parameters:
        n - The maximum number of objects to be loaded into memory.
        See Also:
        getMaxMembers(), setStartMembers(int)
      • getMaxMembers

        public final int getMaxMembers()
        Returns the maximum number of objects that can be loaded into memory.
        Returns:
        The maximum number of objects that can be loaded into memory.
        See Also:
        setMaxMembers(int)
      • setStartMembers

        public final void setStartMembers​(int idx)
        Sets the starting index of objects to be loaded into memory.

        The implementing FileFormat class has freedom in how it indexes objects in the file.

        Parameters:
        idx - The starting index of the object to be loaded into memory
        See Also:
        getStartMembers(), setMaxMembers(int)
      • getStartMembers

        public final int getStartMembers()
        Returns the index of the starting object to be loaded into memory.
        Returns:
        The index of the starting object to be loaded into memory.
        See Also:
        setStartMembers(int)
      • getNumberOfMembers

        public final int getNumberOfMembers()
        Returns the number of objects in memory.

        This method returns the total number of objects loaded into memory for this FileFormat instance. The method counts the objects that are loaded, which can take some time for a large number of objects.

        It is worth noting that the total number of objects in memory may be different than the total number of objects in the file.

        Since implementing classes have freedom in how they interpret and use the maximum number of members value, there may be differing numbers of objects in memory in different implementation instances, even with the same "use case".

        For example, say the use case is a file that contains 20,000 objects, the maximum number of members for an instance is 10,000, and the start member index is 1. There are 2 groups in the file. The root group contains 10,500 objects and the group "/g1" contains 9,500 objects.

        In an implementation that limits the total number of objects loaded to the maximum number of members, this method will return 10,000.

        In contrast, the H5File implementation loads up to the maximum number of members objects for each group in the file. So, with our use case 10,000 objects will be loaded in the root group and 9,500 objects will be loaded into group "/g1". This method will return the value 19,500, which exceeds the maximum number of members value.

        Returns:
        The number of objects in memory.
        See Also:
        getMaxMembers(), setMaxMembers(int), getStartMembers(), setStartMembers(int)
      • open

        public abstract long open()
                           throws Exception
        Opens file and returns a file identifier.

        This method uses the filename and access parameters specified in the createFile(), createInstance(), or getInstance() call to open the file. It returns the file identifier if successful, or a negative value in case of failure.

        The method also loads the file structure and basic information (name, type) for data objects in the file into the FileFormat instance. It does not load the contents of any data object.

        The structure of the file is stored in a tree starting from the root object.

        Returns:
        File identifier if successful; otherwise -1.
        Throws:
        Exception - If the file cannot be opened. The exceptions thrown vary depending on the implementing class.
        See Also:
        createFile(String, int), createInstance(String, int), getInstance(String), getRootObject()
      • close

        public abstract void close()
                            throws Exception
        Closes file associated with this instance.

        This method closes the file associated with this FileFormat instance, as well as all objects associated with the file.

        Throws:
        Exception - If the file or associated objects cannot be closed. The exceptions thrown vary depending on the implementing class.
        See Also:
        open()
      • getRootObject

        public abstract HObject getRootObject()
        Returns the root object for the file associated with this instance.

        The root object is an HObject that represents the root group of a file. If the file has not yet been opened, or if there is no file associated with this instance, null will be returned.

        Starting from the root, applications can descend through the tree structure and navigate among the file's objects. In the tree structure, internal items represent non-empty groups. Leaf items represent datasets, named datatypes, or empty groups.

        Returns:
        The root object of the file, or null if there is no associated file or if the associated file has not yet been opened.
        See Also:
        open()
      • get

        public abstract HObject get​(String path)
                             throws Exception
        Gets the HObject with the specified path from the file.

        This method returns the specified object from the file associated with this FileFormat instance.

        If the specified object is a group, groups and datasets that are members of the group will be accessible via the returned HObject instance. The exact contents of the returned HObject instance depends on whether or not open() was called previously for this file.

        • If the file was opened prior to this method call, the complete tree of objects under the group will be accessible via the returned HObject instance.
        • If the file was not opened prior to this method call, only the members immediately under the group will be accessible via the returned HOBject instance.

        The decision to have different behaviors was made to give users some control over the "cost" of the method. In many cases, a user wants only one level of a tree, and the performance penalty for loading the entire hierarchy of objects in a large and complex file can be significant. In the case where open() has already been called, the HObject instances have already been created in memory and can be returned quickly. If open() has not been called, this method creates the HObject instances before returning the requested HObject.

        For example, say we have the following structure in our file:

                /g0                      Group
                /g0/dataset_comp         Dataset {50, 10}
                /g0/dataset_int          Dataset {50, 10}
                /g0/g00                  Group
                /g0/g00/dataset_float    Dataset {50, 10}
                /g0/g01                  Group
                /g0/g01/dataset_string   Dataset {50, 10}
         
        • If open() is called before get(), the full structure of file is loaded into memory. The call get("/g0") returns the instance for /g0 with the information necessary to access /g0/dataset_comp, /g0/dataset_int, /g0/g00, /g0/g00/dataset_float, /g0/g01, and /g0/g01/dataset_string.
        • If open() is not called before get(), only the objects immediately under the specified group are accessible via the returned HObject instance. In this example, the call get("/go") returns the instance for /g0 with the information necessary to access /g0/dataset_comp, /g0/dataset_int, /g0/g00, and /g0/g01.
        Parameters:
        path - Full path of the data object to be returned.
        Returns:
        The object if it exists in the file; otherwise null.
        Throws:
        Exception - If there are unexpected problems in trying to retrieve the object. The exceptions thrown vary depending on the implementing class.
      • createDatatype

        public abstract Datatype createDatatype​(int tclass,
                                                int tsize,
                                                int torder,
                                                int tsign,
                                                String name)
                                         throws Exception
        Creates a named datatype in a file.

        The following code creates a named datatype in a file.

         H5File file = (H5File) h5file.createInstance("test_hdf5.h5", FileFormat.WRITE);
         H5Datatype dtype = file.createDatatype(
                                     Datatype.CLASS_INTEGER,
                                     4,
                                     Datatype.NATIVE,
                                     Datatype.NATIVE,
                                     "Native Integer");
         
        Parameters:
        tclass - class of datatype, e.g. Datatype.CLASS_INTEGER
        tsize - size of the datatype in bytes, e.g. 4 for 32-bit integer.
        torder - order of the byte endianing, e.g. Datatype.ORDER_LE.
        tsign - signed or unsigned of an integer, e.g. Datatype.SIGN_NONE.
        name - name of the datatype to create, e.g. "Native Integer".
        Returns:
        The new datatype if successful; otherwise returns null.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • createDatatype

        public Datatype createDatatype​(int tclass,
                                       int tsize,
                                       int torder,
                                       int tsign,
                                       Datatype tbase,
                                       String name)
                                throws Exception
        Creates a named datatype in a file.

        The following code creates a named datatype in a file.

         H5File file = (H5File) h5file.createInstance("test_hdf5.h5", FileFormat.WRITE);
         H5Datatype dtype = file.createDatatype(
                                     Datatype.CLASS_INTEGER,
                                     4,
                                     Datatype.NATIVE,
                                     Datatype.NATIVE,
                                     basetype,
                                     "Native Integer");
         
        Parameters:
        tclass - class of datatype, e.g. Datatype.CLASS_INTEGER
        tsize - size of the datatype in bytes, e.g. 4 for 32-bit integer.
        torder - order of the byte endianing, e.g. Datatype.ORDER_LE.
        tsign - signed or unsigned of an integer, e.g. Datatype.SIGN_NONE.
        tbase - the base datatype of the new datatype
        name - name of the datatype to create, e.g. "Native Integer".
        Returns:
        The new datatype if successful; otherwise returns null.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • createDatatype

        public abstract Datatype createDatatype​(int tclass,
                                                int tsize,
                                                int torder,
                                                int tsign)
                                         throws Exception
        Creates a new datatype in memory.

        The following code creates an instance of H5Datatype in memory.

         H5File file = (H5File) h5file.createInstance("test_hdf5.h5", FileFormat.WRITE);
         H5Datatype dtype = file.createDatatype(
                                     Datatype.CLASS_INTEGER,
                                     4,
                                     Datatype.NATIVE,
                                     Datatype.NATIVE);
         
        Parameters:
        tclass - class of datatype, e.g. Datatype.CLASS_INTEGER
        tsize - size of the datatype in bytes, e.g. 4 for 32-bit integer.
        torder - order of the byte endian, e.g. Datatype.ORDER_LE.
        tsign - signed or unsigned of an integer, e.g. Datatype.SIGN_NONE.
        Returns:
        The new datatype object if successful; otherwise returns null.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • createDatatype

        public Datatype createDatatype​(int tclass,
                                       int tsize,
                                       int torder,
                                       int tsign,
                                       Datatype tbase)
                                throws Exception
        Creates a new datatype in memory.

        The following code creates an instance of H5Datatype in memory.

         H5File file = (H5File) h5file.createInstance("test_hdf5.h5", FileFormat.WRITE);
         H5Datatype dtype = file.createDatatype(
                                     Datatype.CLASS_INTEGER,
                                     4,
                                     Datatype.NATIVE,
                                     Datatype.NATIVE,
                                     basetype);
         
        Parameters:
        tclass - class of datatype, e.g. Datatype.CLASS_INTEGER
        tsize - size of the datatype in bytes, e.g. 4 for 32-bit integer.
        torder - order of the byte endian, e.g. Datatype.ORDER_LE.
        tsign - signed or unsigned of an integer, e.g. Datatype.SIGN_NONE.
        tbase - the base datatype of the new datatype
        Returns:
        The new datatype object if successful; otherwise returns null.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • createScalarDS

        public abstract Dataset createScalarDS​(String name,
                                               Group pgroup,
                                               Datatype type,
                                               long[] dims,
                                               long[] maxdims,
                                               long[] chunks,
                                               int gzip,
                                               Object fillValue,
                                               Object data)
                                        throws Exception
        Creates a new dataset in a file with/without chunking/compression.

        The following example creates a 2D integer dataset of size 100X50 at the root group in an HDF5 file.

         String name = "2D integer";
         Group pgroup = (Group) getRootObject();
         Datatype dtype = new H5Datatype(Datatype.CLASS_INTEGER, // class
                 4, // size in bytes
                 Datatype.ORDER_LE, // byte order
                 Datatype.SIGN_NONE); // unsigned
         long[] dims = { 100, 50 };
         long[] maxdims = dims;
         long[] chunks = null; // no
         // chunking
         int gzip = 0; // no compression
         Object data = null; // no initial data values
         Dataset d = (H5File) file.createScalarDS(name, pgroup, dtype, dims, maxdims, chunks, gzip, data);
         
        Parameters:
        name - name of the new dataset, e.g. "2D integer"
        pgroup - parent group where the new dataset is created.
        type - datatype of the new dataset.
        dims - dimension sizes of the new dataset, e.g. long[] dims = {100, 50}.
        maxdims - maximum dimension sizes of the new dataset, null if maxdims is the same as dims.
        chunks - chunk sizes of the new dataset, null if no chunking.
        gzip - GZIP compression level (1 to 9), 0 or negative values if no compression.
        fillValue - default value.
        data - data written to the new dataset, null if no data is written to the new dataset.
        Returns:
        The new dataset if successful; otherwise returns null
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • createScalarDS

        public Dataset createScalarDS​(String name,
                                      Group pgroup,
                                      Datatype type,
                                      long[] dims,
                                      long[] maxdims,
                                      long[] chunks,
                                      int gzip,
                                      Object data)
                               throws Exception
        Throws:
        Exception
      • createCompoundDS

        public Dataset createCompoundDS​(String name,
                                        Group pgroup,
                                        long[] dims,
                                        long[] maxdims,
                                        long[] chunks,
                                        int gzip,
                                        String[] memberNames,
                                        Datatype[] memberDatatypes,
                                        int[] memberSizes,
                                        Object data)
                                 throws Exception
        Creates a new compound dataset in a file with/without chunking and compression.

        The following example creates a compressed 2D compound dataset with size of 100X50 in a root group. The compound dataset has two members, x and y. Member x is an interger, member y is an 1-D float array of size 10.

         String name = "2D compound";
         Group pgroup = (Group) getRootObject();
         long[] dims = {100, 50};
         long[] chunks = {1, 50};
         int gzip = 9;
         String[] memberNames = {"x", "y"};
        
         Datatype[] memberDatatypes = {
             new H5Datatype(Datatype.CLASS_INTEGER, Datatype.NATIVE,
                            Datatype.NATIVE, Datatype.NATIVE)
             new H5Datatype(Datatype.CLASS_FLOAT, Datatype.NATIVE,
                            Datatype.NATIVE, Datatype.NATIVE));
        
         int[] memberSizes = {1, 10};
         Object data = null; // no initial data values
         Dataset d = (H5File)file.createCompoundDS(name, pgroup, dims, null,
                   chunks, gzip, memberNames, memberDatatypes, memberSizes, null);
         
        Parameters:
        name - name of the new dataset
        pgroup - parent group where the new dataset is created.
        dims - dimension sizes of the new dataset.
        maxdims - maximum dimension sizes of the new dataset, null if maxdims is the same as dims.
        chunks - chunk sizes of the new dataset, null if no chunking.
        gzip - GZIP compression level (1 to 9), 0 or negative values if no compression.
        memberNames - names of the members.
        memberDatatypes - datatypes of the members.
        memberSizes - array sizes of the members.
        data - data written to the new dataset, null if no data is written to the new dataset.
        Returns:
        new dataset object if successful; otherwise returns null
        Throws:
        UnsupportedOperationException - If the implementing class does not support compound datasets.
        Exception - The exceptions thrown vary depending on the implementing class.
      • createImage

        public abstract Dataset createImage​(String name,
                                            Group pgroup,
                                            Datatype type,
                                            long[] dims,
                                            long[] maxdims,
                                            long[] chunks,
                                            int gzip,
                                            int ncomp,
                                            int interlace,
                                            Object data)
                                     throws Exception
        Creates a new image in a file.

        The following example creates a 2D image of size 100X50 in a root group.

         String name = "2D image";
         Group pgroup = (Group) getRootObject();
         Datatype dtype = new H5Datatype(Datatype.CLASS_INTEGER, 1, Datatype.NATIVE, Datatype.SIGN_NONE);
         long[] dims = {100, 50};
         long[] maxdims = dims;
         long[] chunks = null; // no chunking
         int gzip = 0; // no compression
         int ncomp = 3; // RGB true color image
         int interlace = ScalarDS.INTERLACE_PIXEL;
         Object data = null; // no initial data values
         Dataset d = (H5File) file.createScalarDS(name, pgroup, dtype, dims, maxdims, chunks, gzip, ncomp, interlace, data);
         
        Parameters:
        name - name of the new image, "2D image".
        pgroup - parent group where the new image is created.
        type - datatype of the new image.
        dims - dimension sizes of the new dataset, e.g. long[] dims = {100, 50}.
        maxdims - maximum dimension sizes of the new dataset, null if maxdims is the same as dims.
        chunks - chunk sizes of the new dataset, null if no chunking.
        gzip - GZIP compression level (1 to 9), 0 or negative values if no compression.
        ncomp - number of components of the new image, e.g. int ncomp = 3; // RGB true color image.
        interlace - interlace mode of the image. Valid values are ScalarDS.INTERLACE_PIXEL, ScalarDS.INTERLACE_PLANEL and ScalarDS.INTERLACE_LINE.
        data - data value of the image, null if no data.
        Returns:
        The new image object if successful; otherwise returns null
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • createGroup

        public abstract Group createGroup​(String name,
                                          Group parentGroup)
                                   throws Exception
        Creates a new group with specified name in existing group.

        If the parent group is null, the new group will be created in the root group.

        Parameters:
        name - The name of the new group.
        parentGroup - The parent group, or null.
        Returns:
        The new group if successful; otherwise returns null.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • createLink

        public HObject createLink​(Group parentGroup,
                                  String name,
                                  HObject currentObj,
                                  int type)
                           throws Exception
        Creates a soft, hard or external link to an existing object in the open file.

        If parentGroup is null, the new link is created in the root group.

        Parameters:
        parentGroup - The group where the link is created.
        name - The name of the link.
        currentObj - The existing object the new link will reference.
        type - The type of link to be created. It can be a hard link, a soft link or an external link.
        Returns:
        The object pointed to by the new link if successful; otherwise returns null.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • createLink

        public HObject createLink​(Group parentGroup,
                                  String name,
                                  String currentObj,
                                  int type)
                           throws Exception
        Creates a soft or external link to an object in a file that does not exist at the time the link is created.
        Parameters:
        parentGroup - The group where the link is created.
        name - The name of the link.
        currentObj - The name of the object the new link will reference. The object doesn't have to exist.
        type - The type of link to be created.
        Returns:
        The H5Link object pointed to by the new link if successful; otherwise returns null.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • copy

        public abstract HObject copy​(HObject srcObj,
                                     Group dstGroup,
                                     String dstName)
                              throws Exception
        Copies the source object to a new destination.

        This method copies the source object to a destination group, and assigns the specified name to the new object.

        The copy may take place within a single file or across files. If the source object and destination group are in different files, the files must have the same file format (both HDF5 for example).

        The source object can be a group, a dataset, or a named datatype. This method copies the object along with all of its attributes and other properties. If the source object is a group, this method also copies all objects and sub-groups below the group.

        The following example shows how to use the copy method to create two copies of an existing HDF5 file structure in a new HDF5 file. One copy will be under /copy1 and the other under /copy2 in the new file.

         // Open the existing file with the source object.
         H5File existingFile = new H5File("existingFile.h5", FileFormat.READ);
         existingFile.open();
         // Our source object will be the root group.
         HObject srcObj = existingFile.get("/");
         // Create a new file.
         H5File newFile = new H5File("newFile.h5", FileFormat.CREATE);
         newFile.open();
         // Both copies in the new file will have the root group as their
         // destination group.
         Group dstGroup = (Group) newFile.get("/");
         // First copy goes to "/copy1" and second goes to "/copy2".
         // Notice that we can use either H5File instance to perform the copy.
         HObject copy1 = existingFile.copy(srcObj, dstGroup, "copy1");
         HObject copy2 = newFile.copy(srcObj, dstGroup, "copy2");
         // Close both the files.
         file.close();
         newFile.close();
         
        Parameters:
        srcObj - The object to copy.
        dstGroup - The destination group for the new object.
        dstName - The name of the new object. If dstName is null, the name of srcObj will be used.
        Returns:
        The new object, or null if the copy fails.
        Throws:
        Exception - are specific to the implementing class.
      • delete

        public abstract void delete​(HObject obj)
                             throws Exception
        Deletes an object from a file.
        Parameters:
        obj - The object to delete.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • writeAttribute

        public abstract void writeAttribute​(HObject obj,
                                            Attribute attr,
                                            boolean attrExisted)
                                     throws Exception
        Attaches a given attribute to an object.

        If an HDF(4&5) attribute exists in file, the method updates its value. If the attribute does not exist in file, it creates the attribute in file and attaches it to the object. It will fail to write a new attribute to the object where an attribute with the same name already exists. To update the value of an existing attribute in file, one needs to get the instance of the attribute by getMetadata(), change its values, and use writeAttribute() to write the value.

        Parameters:
        obj - The object to which the attribute is attached to.
        attr - The atribute to attach.
        attrExisted - The indicator if the given attribute exists.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • create

        @Deprecated
        public final FileFormat create​(String fileName)
                                throws Exception
        Deprecated.
        As of 2.4, replaced by createFile(String, int)

        The replacement method has an additional parameter that controls the behavior if the file already exists. Use FileFormat.FILE_CREATE_DELETE as the second argument in the replacement method to mimic the behavior originally provided by this method.

        Parameters:
        fileName - The filename; a pathname string.
        Returns:
        the created file object
        Throws:
        Exception - if file cannot be created
      • open

        @Deprecated
        public final FileFormat open​(String pathname,
                                     int access)
                              throws Exception
        Deprecated.
        As of 2.4, replaced by createInstance(String, int) The replacement method has identical functionality and a more descriptive name. Since open is used elsewhere to perform a different function this method has been deprecated.
        Parameters:
        pathname - The pathname string.
        access - The file access properties
        Returns:
        the opened file object
        Throws:
        Exception - if the file cannot be opened
      • createCompoundDS

        @Deprecated
        public final Dataset createCompoundDS​(String name,
                                              Group pgroup,
                                              long[] dims,
                                              String[] memberNames,
                                              Datatype[] memberDatatypes,
                                              int[] memberSizes,
                                              Object data)
                                       throws Exception
        Deprecated.
        As of 2.4, replaced by createCompoundDS(String, Group, long[], long[], long[], int, String[], Datatype[], int[], Object)

        The replacement method has additional parameters: maxdims, chunks, and gzip. To mimic the behavior originally provided by this method, call the replacement method with the following parameter list: ( name, pgroup, dims, null, null, -1, memberNames, memberDatatypes, memberSizes, data );

        Parameters:
        name - The dataset name.
        pgroup - The dataset parent.
        dims - The dataset dimensions.
        memberNames - The dataset compound member names.
        memberDatatypes - The dataset compound member datatypes.
        memberSizes - The dataset compound member sizes.
        data - The dataset data.
        Returns:
        The dataset created.
        Throws:
        Exception - if the dataset cannot be created
      • copy

        @Deprecated
        public final HObject copy​(HObject srcObj,
                                  Group dstGroup)
                           throws Exception
        Deprecated.
        As of 2.4, replaced by copy(HObject, Group, String)

        To mimic the behavior originally provided by this method, call the replacement method with null as the 3rd parameter.

        Parameters:
        srcObj - The object to be copied
        dstGroup - The group to contain the copied object
        Returns:
        the copied object
        Throws:
        Exception - if object can not be copied
      • getHObject

        @Deprecated
        public static final HObject getHObject​(String fullPath)
                                        throws Exception
        Deprecated.
        As of 2.4, replaced by get(String)

        This static method, which as been deprecated, causes two problems:

        • It can be very expensive if it is called many times or in a loop because each call to the method creates an instance of a file.
        • Since the method does not return the instance of the file, the file cannot be closed directly and may be left open (memory leak). The only way to close the file is through the object returned by this method.
        Parameters:
        fullPath - The file path string.
        Returns:
        the object that has the given full path
        Throws:
        Exception - if the object can not be found
      • getHObject

        @Deprecated
        public static final HObject getHObject​(String filename,
                                               String path)
                                        throws Exception
        Deprecated.
        As of 2.4, replaced by get(String)

        This static method, which as been deprecated, causes two problems:

        • It can be very expensive if it is called many times or in a loop because each call to the method creates an instance of a file.
        • Since the method does not return the instance of the file, the file cannot be closed directly and may be left open (memory leak). The only way to close the file is through the object returned by this method, for example:
           Dataset dset = H5File.getObject("hdf5_test.h5", "/images/iceburg");
           ...
           // close the file through dset
           dset.getFileFormat().close();
           
        Parameters:
        filename - The filename string.
        path - The path of the file
        Returns:
        the object that has the given filename and path returns null
        Throws:
        Exception - if the object can not be found
      • findObject

        public static final HObject findObject​(FileFormat file,
                                               long[] oid)
        Finds an object by its object ID
        Parameters:
        file - the file containing the object
        oid - the oid to search for
        Returns:
        the object that has the given OID; otherwise returns null
      • findObject

        public static final HObject findObject​(FileFormat file,
                                               String path)
        Finds an object by the full path of the object (path+name)
        Parameters:
        file - the file containing the object
        path - the full path of the object to search for
        Returns:
        the object that has the given path; otherwise returns null
      • open

        public long open​(int... indexList)
                  throws Exception
        Opens file and returns a file identifier.
        Parameters:
        indexList - The property list is the list of parameters, like index type and the index order. The index type can be alphabetical or creation. The index order can be increasing order or decreasing order.
        Returns:
        File identifier if successful; otherwise -1.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • createGroup

        public Group createGroup​(String name,
                                 Group pgroup,
                                 long... gplist)
                          throws Exception
        Creates a new group with specified name in existing group.

        If the parent group is null, the new group will be created in the root group.

        Parameters:
        name - The name of a new group.
        pgroup - The parent group object.
        gplist - The group creation properties, in which the order of the properties conforms the HDF5 library API, H5Gcreate(), i.e. lcpl, gcpl and gapl, where
        • lcpl : Property list for link creation
        • gcpl : Property list for group creation
        • gapl : Property list for group access
        Returns:
        The new group if successful; otherwise returns null.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • createGcpl

        public long createGcpl​(int creationorder,
                               int maxcompact,
                               int mindense)
                        throws Exception
        Creates the group creation property list identifier, gcpl. This identifier is used when creating Groups.
        Parameters:
        creationorder - The order in which the objects in a group should be created. It can be Tracked or Indexed.
        maxcompact - The maximum number of links to store in the group in a compact format.
        mindense - The minimum number of links to store in the indexed format.Groups which are in indexed format and in which the number of links falls below this threshold are automatically converted to compact format.
        Returns:
        The gcpl identifier.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • createLink

        public HObject createLink​(Group linkGroup,
                                  String name,
                                  Object currentObj)
                           throws Exception
        Creates a link to an existing object in the open file.

        If linkGroup is null, the new link is created in the root group.

        Parameters:
        linkGroup - The group where the link is created.
        name - The name of the link.
        currentObj - The existing object the new link will reference.
        Returns:
        The object pointed to by the new link if successful; otherwise returns null.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • exportDataset

        public void exportDataset​(String file_export_name,
                                  String file_name,
                                  String object_path,
                                  int binary_order)
                           throws Exception
        Export dataset.
        Parameters:
        file_export_name - The file name to export data into.
        file_name - The name of the HDF5 file containing the dataset.
        object_path - The full path of the dataset to be exported.
        binary_order - The data byte order
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • renameAttribute

        public void renameAttribute​(HObject obj,
                                    String oldAttrName,
                                    String newAttrName)
                             throws Exception
        Renames an attribute.
        Parameters:
        obj - The object whose attribute is to be renamed.
        oldAttrName - The current name of the attribute.
        newAttrName - The new name of the attribute.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • setNewLibBounds

        public void setNewLibBounds​(String lowStr,
                                    String highStr)
                             throws Exception
        Sets the bounds of new library versions.
        Parameters:
        lowStr - The earliest version of the library.
        highStr - The latest version of the library.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • setLibBounds

        public void setLibBounds​(String lowStr,
                                 String highStr)
                          throws Exception
        Sets the bounds of library versions.
        Parameters:
        lowStr - The earliest version of the library.
        highStr - The latest version of the library.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • getLibBounds

        public int[] getLibBounds()
                           throws Exception
        Gets the bounds of library versions
        Returns:
        The earliest and latest library versions in an int array.
        Throws:
        Exception - The exceptions thrown vary depending on the implementing class.
      • getIndexType

        public int getIndexType​(String strtype)
      • setIndexType

        public void setIndexType​(int indexType)