- All Implemented Interfaces:
Serializable
,Comparable<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:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
File access flag for creating/truncating with read-write permission.protected long
File identifier.static final int
Flag for creating/truncating a file.static final int
Flag to indicate if the earliest version of library is used when creating a new file.static final int
Flag for creating/opening a file.static final String
A separator that separates file name and object name.static final String
Key for HDF4 file format.static final String
Key for HDF5 file format.static final String
Key for NetCDF file format.protected String
The absolute pathname (path+name) of the file.protected boolean
Flag indicating if the file access is read-only.static final int
File access flag for multi-read-only permission.static final int
File first time access flag for open file.static final int
File access flag for read-only permission.static final int
File access flag for read/write permission.Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
-
Constructor Summary
ConstructorDescriptionFileFormat
(String filename) Creates a new FileFormat instance with the given filename. -
Method Summary
Modifier and TypeMethodDescriptionstatic final void
addFileExtension
(String extension) Adds file extension(s) to the list of file extensions for supported file formats.static final 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.final HObject
Deprecated.abstract HObject
Copies the source object to a new destination.final FileFormat
Deprecated.As of 2.4, replaced bycreateFile(String, int)
The replacement method has an additional parameter that controls the behavior if the file already exists.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.final Dataset
createCompoundDS
(String name, Group pgroup, long[] dims, String[] memberNames, Datatype[] memberDatatypes, int[] memberSizes, Object data) Deprecated.As of 2.4, replaced bycreateCompoundDS(String, Group, long[], long[], long[], int, String[], Datatype[], int[], Object)
The replacement method has additional parameters:maxdims, chunks,
andgzip
.abstract Datatype
createDatatype
(int tclass, int tsize, int torder, int tsign) Creates a new datatype in memory.createDatatype
(int tclass, int tsize, int torder, int tsign, Datatype tbase) Creates a new datatype in memory.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.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.createLink
(Group parentGroup, String name, HObject currentObj, int type) Creates a soft, hard or external link to an existing object in the open file.createLink
(Group linkGroup, String name, Object currentObj) Creates a link to an existing object in the open file.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.createNamedDatatype
(Datatype tnative, String name) Creates a named datatype in a file.createScalarDS
(String name, Group pgroup, Datatype type, long[] dims, long[] maxdims, long[] chunks, int gzip, Object data) Creates a new dataset in a file with/without chunking/compression.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
Deletes an object from a file.void
exportDataset
(String file_export_name, Dataset object, int binary_order) Export dataset.static final HObject
findObject
(FileFormat file, long[] oid) Finds an object by its object IDstatic final HObject
findObject
(FileFormat file, String path) Finds an object by the full path of the object (path+name)abstract HObject
Gets the HObject with the specified path from the file.final long
getFID()
Returns file identifier of open file associated with this instance.static final String
Returns a list of file extensions for all supported file formats.static final FileFormat
getFileFormat
(String key) Returns the FileFormat with specified key from the list of supported formats.static final Enumeration
Returns an Enumeration of keys for all supported formats.static final FileFormat[]
Returns an array of supported FileFormat instances.final String
Returns the absolute path for the file.static final HObject
getHObject
(String fullPath) Deprecated.As of 2.4, replaced byget(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.static final HObject
getHObject
(String filename, String path) Deprecated.As of 2.4, replaced byget(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.int
getIndexOrder
(String strorder) Get the value of the index order.static int
getIndexOrderValue
(String strorder) Get the value of the index order value.int
getIndexType
(String strtype) Get the value of the index type.static int
getIndexTypeValue
(String strtype) Get the value of the index type value.static final FileFormat
getInstance
(String filename) Creates a FileFormat instance for the specified file.int[]
Gets the bounds of library versionsGets the bounds of library versions as text.abstract String
Returns the version of the library for the implementing FileFormat class.final int
Returns the maximum number of objects that can be loaded into memory.final int
Returns the number of objects in memory.abstract HObject
Returns the root object for the file associated with this instance.final int
Returns the index of the starting object to be loaded into memory.void
Initialize the bounds of library versionsfinal boolean
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.final FileFormat
Deprecated.As of 2.4, replaced bycreateInstance(String, int)
The replacement method has identical functionality and a more descriptive name.static final 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) set the int value of the index order.void
setIndexType
(int indexType) set the int value of the index type.void
setLibBounds
(String lowStr, String highStr) Sets the bounds of library versions.final 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.final 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
-
Field Details
-
OPEN_NEW
File first time access flag for open file. With this access flag, added to the regular value, indicates this file has no existing state.- See Also:
-
READ
File access flag for read-only permission. With this access flag, modifications to the file will not be allowed.- See Also:
-
WRITE
File access flag for read/write permission. With this access flag, modifications to the file will be allowed. Behavior if the file does not exist or cannot be opened for read/write access depends on the implementing class.- See Also:
-
CREATE
File access flag for creating/truncating with read-write permission. If the file already exists, it will be truncated when opened. With this access flag, modifications to the file will be allowed. Behavior if file can't be created, or if it exists but can't be opened for read/write access, depends on the implementing class.- See Also:
-
MULTIREAD
File access flag for multi-read-only permission. With this access flag, modifications to the file will not be allowed.- See Also:
-
FILE_CREATE_DELETE
Flag for creating/truncating a file. If the file already exists, it will be truncated when opened. If the file does not exist, it will be created. Modifications to the file will be allowed.- See Also:
-
FILE_CREATE_OPEN
Flag for creating/opening a file. If the file already exists, it will be opened without changing the existing contents. If the file does not exist, it will be created. Modifications to the file will be allowed.- See Also:
-
FILE_CREATE_EARLY_LIB
Flag to indicate if the earliest version of library is used when creating a new file.- See Also:
-
FILE_TYPE_HDF4
-
FILE_TYPE_HDF5
-
FILE_TYPE_NC3
-
FILE_OBJ_SEP
A separator that separates file name and object name.- See Also:
-
fid
File identifier. -1 indicates the file is not open. -
fullFileName
The absolute pathname (path+name) of the file. -
isReadOnly
Flag indicating if the file access is read-only.
-
-
Constructor Details
-
FileFormat
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 thefilename
argument isnull
.- See Also:
-
-
Method Details
-
addFileFormat
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 eitherkey
orfileformat
arenull
, or ifkey
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
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:
-
getFileFormatKeys
Returns an Enumeration of keys for all supported formats. This method returns an Enumeration containing the unique keys (Strings) for the all File Formats in the list of supported File Formats.- Returns:
- An Enumeration of keys that are in the list of supported formats.
- See Also:
-
getFileFormats
Returns an array of supported FileFormat instances. This method returns an array of FileFormat instances that appear in the list of supported File Formats. If the list of supported formats is empty,null
is returned.- Returns:
- An array of all FileFormat instances in the list of supported
File Formats, or
null
if the list is empty. - See Also:
-
removeFileFormat
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:
-
addFileExtension
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:
-
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 usingaddFileExtension(String)
when new FileFormat implementations are added.- Returns:
- A list of file extensions for all supported file formats.
- See Also:
-
getInstance
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 thefilename
argument isnull
or does not specify an existing file.Exception
- If there are problems creating the new instance.- See Also:
-
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
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
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 returnfalse
, and the second call will returntrue
.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:
-
createFile
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.
- Parameters:
filename
- The filename; a pathname string.createFlag
- The creation flag, which determines behavior when the file already exists. Acceptable values areFILE_CREATE_DELETE
andFILE_CREATE_OPEN
.- Returns:
- the FileFormat instance.
- Throws:
NullPointerException
- If thefilename
argument isnull
.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
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.
- SWMR: 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.
// 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 areREAD, WRITE,
andCREATE
.- Returns:
- the FileFormat instance.
- Throws:
NullPointerException
- If thefilename
argument isnull
.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:
-
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
Returns file identifier of open file associated with this instance.- Returns:
- The file identifer, or -1 if there is no file open.
-
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:
-
setMaxMembers
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
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:
-
setStartMembers
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
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:
-
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:
-
open
Opens file and returns a file identifier. This method uses thefilename
andaccess
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:
-
close
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:
-
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:
-
get
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 notopen()
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.
/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.
-
createNamedDatatype
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.createNamedDatatype( nativetype, "Native Integer");
- Parameters:
tnative
- the native datatype of the new datatypename
- 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_INTEGERtsize
- 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_INTEGERtsize
- 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 Creates a new dataset in a file with/without chunking/compression.- 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.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.
-
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 datasetpgroup
- 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
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
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
-
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.As of 2.4, replaced bycreateFile(String, int)
The replacement method has an additional parameter that controls the behavior if the file already exists. UseFileFormat.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.As of 2.4, replaced bycreateInstance(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 bycreateCompoundDS(String, Group, long[], long[], long[], int, String[], Datatype[], int[], Object)
The replacement method has additional parameters:maxdims, chunks,
andgzip
. 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.As of 2.4, replaced bycopy(HObject, Group, String)
To mimic the behavior originally provided by this method, call the replacement method withnull
as the 3rd parameter.- Parameters:
srcObj
- The object to be copieddstGroup
- The group to contain the copied object- Returns:
- the copied object
- Throws:
Exception
- if object can not be copied
-
getHObject
Deprecated.As of 2.4, replaced byget(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.As of 2.4, replaced byget(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
Finds an object by its object ID- Parameters:
file
- the file containing the objectoid
- the oid to search for- Returns:
- the object that has the given OID; otherwise returns null
-
findObject
Finds an object by the full path of the object (path+name)- Parameters:
file
- the file containing the objectpath
- the full path of the object to search for- Returns:
- the object that has the given path; otherwise returns null
-
open
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
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
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
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, Dataset object, int binary_order) throws Exception Export dataset.- Parameters:
file_export_name
- The file name to export data into.object
- The HDF5 dataset object.binary_order
- The data byte order- Throws:
Exception
- The exceptions thrown vary depending on the implementing class.
-
renameAttribute
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
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
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
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.
-
initLibBounds
Initialize the bounds of library versions- Throws:
Exception
- The exceptions thrown vary depending on the implementing class.
-
getLibBoundsDescription
Gets the bounds of library versions as text.- Returns:
- libversion The earliest and latest version of the library.
- Throws:
Exception
- The exceptions thrown vary depending on the implementing class.
-
getIndexTypeValue
Get the value of the index type value.- Parameters:
strtype
- The name of the index type.- Returns:
- the int value of the index type value.
- Throws:
Exception
- The exceptions thrown vary depending on the implementing class.
-
getIndexType
Get the value of the index type.- Parameters:
strtype
- The name of the index type.- Returns:
- the int value of the index type.
- Throws:
Exception
- The exceptions thrown vary depending on the implementing class.
-
setIndexType
set the int value of the index type.- Parameters:
indexType
- The value of the index type.- Throws:
Exception
- The exceptions thrown vary depending on the implementing class.
-
getIndexOrderValue
Get the value of the index order value.- Parameters:
strorder
- The name of the index order.- Returns:
- the int value of the index order value.
- Throws:
Exception
- The exceptions thrown vary depending on the implementing class.
-
getIndexOrder
Get the value of the index order.- Parameters:
strorder
- The name of the index order.- Returns:
- the int value of the index order.
- Throws:
Exception
- The exceptions thrown vary depending on the implementing class.
-
setIndexOrder
set the int value of the index order.- Parameters:
indexOrder
- The index order.- Throws:
Exception
- The exceptions thrown vary depending on the implementing class.
-
copy(HObject, Group, String)
To mimic the behavior originally provided by this method, call the replacement method withnull
as the 3rd parameter.