- All Implemented Interfaces:
- CompoundDataFormat,- DataFormat,- MetaDataContainer,- Serializable
- Direct Known Subclasses:
- H4Attribute,- H5Attribute,- NC2Attribute
Like a dataset, an attribute has a name, datatype and dataspace.
For more details on attributes, HDF5 User's Guide
The following code is an example of an attribute with 1D integer array of two elements.
 // Example of creating a new attribute
 // The name of the new attribute
 String name = "Data range";
 // Creating an unsigned 1-byte integer datatype
 Datatype type = new Datatype(Datatype.CLASS_INTEGER, // class
                              1,                      // size in bytes
                              Datatype.ORDER_LE,      // byte order
                              Datatype.SIGN_NONE);    // unsigned
 // 1-D array of size two
 long[] dims = {2};
 // The value of the attribute
 int[] value = {0, 255};
 // Create a new attribute
 Attribute dataRange = new Attribute(name, type, dims);
 // Set the attribute value
 dataRange.setValue(value);
 // See FileFormat.writeAttribute() for how to attach an attribute to an object,
 @see hdf.object.FileFormat#writeAttribute(HObject, Attribute, boolean)
 
 For an atomic datatype, the value of an Attribute will be a 1D array of integers, floats and
 strings. For a compound datatype, it will be a 1D array of strings with field members separated
 by a comma. For example, "{0, 10.5}, {255, 20.0}, {512, 30.0}" is a compound attribute of {int,
 float} of three data points.- Version:
- 2.0 4/2/2018
- Author:
- Peter X. Cao, Jordan T. Henderson
- See Also:
- Datatype, Serialized Form
- 
Field SummaryFieldsModifier and TypeFieldDescriptionA list of names of all compound fields including nested fields.A list of datatypes of all compound fields including nested fields.protected boolean[]The array to store flags to indicate if a member of this compound attribute is selected for read/write.protected booleanFlag to indicate if the attribute data is a single scalar pointprotected Object[]The dimension sizes of each member.protected String[]The names of the members of the compound attribute.protected int[]Array containing the total number of elements of the members of this compound attribute.protected Datatype[]The datatypes of the compound attribute's members.protected intThe number of members of the compound attribute.protected HObjectThe HObject to which this Attribute is attachedprotected booleanFlag to indicate is the original unsigned C data is converted.Fields inherited from class hdf.object.DatasetchunkSize, compression, COMPRESSION_GZIP_TXT, convertByteToString, convertedBuf, data, datatype, dimNames, dims, filters, inited, isDataLoaded, maxDims, nPoints, originalBuf, rank, selectedDims, selectedIndex, selectedStride, startDims, storage, storageLayoutFields inherited from class hdf.object.HObjectfileFormat, linkTargetObjName, oid, SEPARATOR
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidClears the current data buffer in memory and forces the next read() to load the data from file.voidclose(long aid)Closes access to the object.protected ObjectconvertCompoundByteMember(byte[] data, long data_type, long start, long len)Given an array of bytes representing a compound Datatype and a start index and length, converts len number of bytes into the correct Object type and returns it.Converts the data values of this Attribute to appropriate Java integers if they are unsigned integers.Converts Java integer data values of this Attribute back to unsigned C-type integer data if they are unsigned integers.Creates a new dataset and writes the data buffer to the new dataset.booleanReturns whether this Attribute is equal to the specified HObject by comparing various properties.Returns the datatype of the data object.Returns the fill values for the data object.intReturns the number of members of the compound attribute.int[]getMemberDims(int i)Returns the dimension sizes of the i-th member.String[]Returns the names of the members of the compound attribute.int[]Returns array containing the total number of elements of the members of the compound attribute.Datatype[]Returns an array of datatype objects of compound members.Retrieves the object's metadata, such as attributes, from the file.Returns the HObject to which this Attribute is currently "attached".getProperty(String key)get a property for a given key.get all property keys.intReturns the number of selected members of the compound attribute.String[]Returns an array of the names of the selected members of the compound dataset.int[]Returns array containing the total number of elements of the selected members of the compound attribute.Datatype[]Returns an array of datatype objects of selected compound members.booleanCheck if the object has any attributes attached.inthashCode()voidinit()booleanisMemberSelected(int idx)Checks if a member of the compound attribute is selected for read/write.booleanisScalar()longopen()Opens an existing object such as a dataset or group for access.read()Reads the data from file.byte[]Reads the raw data of the dataset from file to a byte array.voidremoveMetadata(Object metadata)Deletes an existing piece of metadata from this object.protected voidvoidselectMember(int idx)Selects the i-th member for read/write.voidsetAllMemberSelection(boolean selectAll)Selects/deselects all members.voidsetParentObject(HObject pObj)Sets the HObject to which this Attribute is "attached".voidsetProperty(String key, Object value)set a property for the attribute.Returns a string representation of the data value of the attribute.Returns a string representation of the data value of the attribute.voidupdateMetadata(Object metadata)Updates an existing piece of metadata attached to this object.voidWrites a memory buffer to the object in the file.voidwriteMetadata(Object metadata)Writes a specific piece of metadata (such as an attribute) into the file.Methods inherited from class hdf.object.DatasetbyteToString, clear, convertFromUnsignedC, convertFromUnsignedC, convertToUnsignedC, convertToUnsignedC, getChunkSize, getCompression, getConvertByteToString, getData, getDimNames, getDims, getFilters, getHeight, getMaxDims, getOriginalClass, getRank, getSelectedDims, getSelectedIndex, getSize, getStartDims, getStorage, getStorageLayout, getStride, getVirtualFilename, getVirtualMaps, getWidth, isInited, isString, isVirtual, setConvertByteToString, setData, stringToByte, writeMethods inherited from class hdf.object.HObjectcreateFullname, debug, equals, equalsOID, getFID, getFile, getFileFormat, getFullName, getLinkTargetObjName, getName, getOID, getPath, setFullname, setLinkTargetObjName, setName, setPath, toStringMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface hdf.object.DataFormatgetCompression, getData, getDims, getHeight, getOriginalClass, getRank, getSelectedDims, getSelectedIndex, getStartDims, getStride, getWidth, isInited, setData, write
- 
Field Details- 
parentObjectThe HObject to which this Attribute is attached
- 
unsignedConvertedFlag to indicate is the original unsigned C data is converted.
- 
isScalarFlag to indicate if the attribute data is a single scalar point
- 
flatNameListA list of names of all compound fields including nested fields.The nested names are separated by CompoundDS.SEPARATOR. For example, if compound attribute "A" has the following nested structure, A --> m01 A --> m02 A --> nest1 --> m11 A --> nest1 --> m12 A --> nest1 --> nest2 --> m21 A --> nest1 --> nest2 --> m22 i.e. A = { m01, m02, nest1{m11, m12, nest2{ m21, m22}}}The flatNameList of compound attribute "A" will be {m01, m02, nest1[m11, nest1[m12, nest1[nest2[m21, nest1[nest2[m22}
- 
flatTypeListA list of datatypes of all compound fields including nested fields.
- 
numberOfMembersThe number of members of the compound attribute.
- 
memberNamesThe names of the members of the compound attribute.
- 
memberOrdersArray containing the total number of elements of the members of this compound attribute.For example, a compound attribute COMP has members of A, B and C as COMP { int A; float B[5]; double C[2][3]; }memberOrders is an integer array of {1, 5, 6} to indicate that member A has one element, member B has 5 elements, and member C has 6 elements.
- 
memberDimsThe dimension sizes of each member.The i-th element of the Object[] is an integer array (int[]) that contains the dimension sizes of the i-th member. 
- 
memberTypesThe datatypes of the compound attribute's members.
- 
isMemberSelectedThe array to store flags to indicate if a member of this compound attribute is selected for read/write.If a member is selected, the read/write will perform on the member. Applications such as HDFView will only display the selected members of the compound attribute. For example, if a compound attribute has four members String[] memberNames = {"X", "Y", "Z", "TIME"}; and boolean[] isMemberSelected = {true, false, false, true}; members "X" and "TIME" are selected for read and write.
 
- 
- 
Constructor Details- 
AttributeCreate an attribute with specified name, data type and dimension sizes. For scalar attribute, the dimension size can be either an array of size one or null, and the rank can be either 1 or zero. Attribute is a general class and is independent of file format, e.g., the implementation of attribute applies to both HDF4 and HDF5.The following example creates a string attribute with the name "CLASS" and value "IMAGE". long[] attrDims = { 1 }; String attrName = "CLASS"; String[] classValue = { "IMAGE" }; Datatype attrType = null; try { attrType = new H5Datatype(Datatype.CLASS_STRING, classValue[0].length() + 1, Datatype.NATIVE, Datatype.NATIVE); } catch (Exception ex) {} Attribute attr = new Attribute(attrName, attrType, attrDims); attr.setValue(classValue);- Parameters:
- parentObj- the HObject to which this Attribute is attached.
- attrName- the name of the attribute.
- attrType- the datatype of the attribute.
- attrDims- the dimension sizes of the attribute, null for scalar attribute
- See Also:
- Datatype
 
- 
Attributepublic Attribute(HObject parentObj, String attrName, Datatype attrType, long[] attrDims, Object attrValue)Create an attribute with specific name and value. For scalar attribute, the dimension size can be either an array of size one or null, and the rank can be either 1 or zero. Attribute is a general class and is independent of file format, e.g., the implementation of attribute applies to both HDF4 and HDF5.The following example creates a string attribute with the name "CLASS" and value "IMAGE". long[] attrDims = { 1 }; String attrName = "CLASS"; String[] classValue = { "IMAGE" }; Datatype attrType = null; try { attrType = new H5Datatype(Datatype.CLASS_STRING, classValue[0].length() + 1, Datatype.NATIVE, Datatype.NATIVE); } catch (Exception ex) {} Attribute attr = new Attribute(attrName, attrType, attrDims, classValue);- Parameters:
- parentObj- the HObject to which this Attribute is attached.
- attrName- the name of the attribute.
- attrType- the datatype of the attribute.
- attrDims- the dimension sizes of the attribute, null for scalar attribute
- attrValue- the value of the attribute, null if no value
- See Also:
- Datatype
 
 
- 
- 
Method Details- 
openDescription copied from class:HObjectOpens an existing object such as a dataset or group for access. The return value is an object identifier obtained by implementing classes such as H5.H5Dopen(). This function is needed to allow other objects to be able to access the object. For instance, H5File class uses the open() function to obtain object identifier for copyAttributes(long src_id, long dst_id) and other purposes. The open() function should be used in pair with close(long) function.- Specified by:
- openin class- HObject
- Returns:
- the object identifier if successful; otherwise returns a negative value.
- See Also:
- HObject.close(long)
 
- 
closeDescription copied from class:HObjectCloses access to the object.Sub-classes must implement this interface because different data objects have their own ways of how the data resources are closed. For example, H5Group.close() calls the hdf.hdf5lib.H5.H5Gclose() method and closes the group resource specified by the group id. 
- 
init- Specified by:
- initin interface- DataFormat
 
- 
getParentObjectReturns the HObject to which this Attribute is currently "attached".- Returns:
- the HObject to which this Attribute is currently "attached".
 
- 
setParentObjectSets the HObject to which this Attribute is "attached".- Parameters:
- pObj- the new HObject to which this Attribute is "attached".
 
- 
convertFromUnsignedCConverts the data values of this Attribute to appropriate Java integers if they are unsigned integers.- Specified by:
- convertFromUnsignedCin interface- DataFormat
- Returns:
- the converted data buffer.
- See Also:
- Dataset.convertToUnsignedC(Object),- Dataset.convertFromUnsignedC(Object, Object)
 
- 
convertToUnsignedCConverts Java integer data values of this Attribute back to unsigned C-type integer data if they are unsigned integers.- Specified by:
- convertToUnsignedCin interface- DataFormat
- Returns:
- the converted data buffer.
- See Also:
- Dataset.convertToUnsignedC(Object),- Dataset.convertToUnsignedC(Object, Object),- Dataset.convertFromUnsignedC(Object data_in)
 
- 
getFillValueDescription copied from interface:DataFormatReturns the fill values for the data object.- Specified by:
- getFillValuein interface- DataFormat
- Returns:
- the fill values for the data object.
 
- 
clearDataDescription copied from class:DatasetClears the current data buffer in memory and forces the next read() to load the data from file.The function read() loads data from file into memory only if the data is not read. If data is already in memory, read() just returns the memory buffer. Sometimes we want to force read() to re-read data from file. For example, when the selection is changed, we need to re-read the data. - Specified by:
- clearDatain interface- DataFormat
- Overrides:
- clearDatain class- Dataset
- See Also:
- Dataset.getData(),- DataFormat.read()
 
- 
resetSelection
- 
setPropertyset a property for the attribute.- Parameters:
- key- the attribute Map key
- value- the attribute Map value
 
- 
getPropertyget a property for a given key.- Parameters:
- key- the attribute Map key
- Returns:
- the property
 
- 
getPropertyKeysget all property keys.- Returns:
- the Collection of property keys
 
- 
isScalar- Returns:
- true if the data is a single scalar point; otherwise, returns false.
 
- 
readDescription copied from interface:DataFormatReads the data from file.read() reads the data from file to a memory buffer and returns the memory buffer. The dataset object does not hold the memory buffer. To store the memory buffer in the dataset object, one must call getData(). By default, the whole dataset is read into memory. Users can also select a subset to read. Subsetting is done in an implicit way. - Specified by:
- readin interface- DataFormat
- Returns:
- the data read from file.
- Throws:
- Exception- if object can not be read
- OutOfMemoryError- if memory is exhausted
- See Also:
- DataFormat.getData()
 
- 
writeDescription copied from interface:DataFormatWrites a memory buffer to the object in the file.- Specified by:
- writein interface- DataFormat
- Parameters:
- buf- the data to write
- Throws:
- Exception- if data can not be written
 
- 
getMemberCountReturns the number of members of the compound attribute.- Specified by:
- getMemberCountin interface- CompoundDataFormat
- Returns:
- the number of members of the compound attribute.
 
- 
getSelectedMemberCountReturns the number of selected members of the compound attribute. Selected members are the compound fields which are selected for read/write.For example, in a compound datatype of {int A, float B, char[] C}, users can choose to retrieve only {A, C} from the attribute. In this case, getSelectedMemberCount() returns two. - Specified by:
- getSelectedMemberCountin interface- CompoundDataFormat
- Returns:
- the number of selected members.
 
- 
getMemberNamesReturns the names of the members of the compound attribute. The names of compound members are stored in an array of Strings.For example, for a compound datatype of {int A, float B, char[] C} getMemberNames() returns ["A", "B", "C"}. - Specified by:
- getMemberNamesin interface- CompoundDataFormat
- Returns:
- the names of compound members.
 
- 
getSelectedMemberNamesReturns an array of the names of the selected members of the compound dataset.- Specified by:
- getSelectedMemberNamesin interface- CompoundDataFormat
- Returns:
- an array of the names of the selected members of the compound dataset.
 
- 
isMemberSelectedChecks if a member of the compound attribute is selected for read/write.- Specified by:
- isMemberSelectedin interface- CompoundDataFormat
- Parameters:
- idx- the index of compound member.
- Returns:
- true if the i-th memeber is selected; otherwise returns false.
 
- 
selectMemberSelects the i-th member for read/write.- Specified by:
- selectMemberin interface- CompoundDataFormat
- Parameters:
- idx- the index of compound member.
 
- 
setAllMemberSelectionSelects/deselects all members.- Specified by:
- setAllMemberSelectionin interface- CompoundDataFormat
- Parameters:
- selectAll- The indicator to select or deselect all members. If true, all members are selected for read/write. If false, no member is selected for read/write.
 
- 
getMemberOrdersReturns array containing the total number of elements of the members of the compound attribute.For example, a compound attribute COMP has members of A, B and C as COMP { int A; float B[5]; double C[2][3]; }getMemberOrders() will return an integer array of {1, 5, 6} to indicate that member A has one element, member B has 5 elements, and member C has 6 elements.- Specified by:
- getMemberOrdersin interface- CompoundDataFormat
- Returns:
- the array containing the total number of elements of the members of the compound attribute.
 
- 
getSelectedMemberOrdersReturns array containing the total number of elements of the selected members of the compound attribute.For example, a compound attribute COMP has members of A, B and C as COMP { int A; float B[5]; double C[2][3]; }If A and B are selected, getSelectedMemberOrders() returns an array of {1, 5}- Specified by:
- getSelectedMemberOrdersin interface- CompoundDataFormat
- Returns:
- array containing the total number of elements of the selected members of the compound attribute.
 
- 
getMemberDimsReturns the dimension sizes of the i-th member.For example, a compound attribute COMP has members of A, B and C as COMP { int A; float B[5]; double C[2][3]; }getMemberDims(2) returns an array of {2, 3}, while getMemberDims(1) returns an array of {5}, and getMemberDims(0) returns null.- Specified by:
- getMemberDimsin interface- CompoundDataFormat
- Parameters:
- i- the i-th member
- Returns:
- the dimension sizes of the i-th member, null if the compound member is not an array.
 
- 
getMemberTypesReturns an array of datatype objects of compound members.Each member of a compound attribute has its own datatype. The datatype of a member can be atomic or other compound datatype (nested compound). The datatype objects are setup at init(). - Specified by:
- getMemberTypesin interface- CompoundDataFormat
- Returns:
- the array of datatype objects of the compound members.
 
- 
getSelectedMemberTypesReturns an array of datatype objects of selected compound members.- Specified by:
- getSelectedMemberTypesin interface- CompoundDataFormat
- Returns:
- an array of datatype objects of selected compound members.
 
- 
getMetadataDescription copied from interface:MetaDataContainerRetrieves the object's metadata, such as attributes, from the file.Metadata, such as attributes, is stored in a List. - Specified by:
- getMetadatain interface- MetaDataContainer
- Returns:
- the list of metadata objects.
- Throws:
- Exception- if the metadata can not be retrieved
 
- 
writeMetadataDescription copied from interface:MetaDataContainerWrites a specific piece of metadata (such as an attribute) into the file. If an HDF(4&5) attribute exists in the file, this method updates its value. If the attribute does not exist in the file, it creates the attribute in the 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 the file, one needs to get the instance of the attribute by getMetadata(), change its values, then use writeMetadata() to write the value.- Specified by:
- writeMetadatain interface- MetaDataContainer
- Parameters:
- metadata- the metadata to write.
- Throws:
- Exception- if the metadata can not be written
 
- 
removeMetadataDescription copied from interface:MetaDataContainerDeletes an existing piece of metadata from this object.- Specified by:
- removeMetadatain interface- MetaDataContainer
- Parameters:
- metadata- the metadata to delete.
- Throws:
- Exception- if the metadata can not be removed
 
- 
updateMetadataDescription copied from interface:MetaDataContainerUpdates an existing piece of metadata attached to this object.- Specified by:
- updateMetadatain interface- MetaDataContainer
- Parameters:
- metadata- the metadata to update.
- Throws:
- Exception- if the metadata can not be updated
 
- 
hasAttributeDescription copied from interface:MetaDataContainerCheck if the object has any attributes attached.- Specified by:
- hasAttributein interface- MetaDataContainer
- Returns:
- true if it has any attributes, false otherwise.
 
- 
getDatatypeDescription copied from interface:DataFormatReturns the datatype of the data object.- Specified by:
- getDatatypein interface- DataFormat
- Overrides:
- getDatatypein class- Dataset
- Returns:
- the datatype of the data object.
 
- 
readBytesDescription copied from class:DatasetReads the raw data of the dataset from file to a byte array.readBytes() reads raw data to an array of bytes instead of array of its datatype. For example, for a one-dimension 32-bit integer dataset of size 5, readBytes() returns a byte array of size 20 instead of an int array of 5. readBytes() can be used to copy data from one dataset to another efficiently because the raw data is not converted to its native type, it saves memory space and CPU time. 
- 
copyDescription copied from class:DatasetCreates a new dataset and writes the data buffer to the new dataset.This function allows applications to create a new dataset for a given data buffer. For example, users can select a specific interesting part from a large image and create a new image with the selection. The new dataset retains the datatype and dataset creation properties of this dataset. - Specified by:
- copyin class- Dataset
- Parameters:
- pgroup- the group which the dataset is copied to.
- name- the name of the new dataset.
- dims- the dimension sizes of the the new dataset.
- data- the data values of the subset to be copied.
- Returns:
- the new dataset.
- Throws:
- Exception- if dataset can not be copied
 
- 
equalsReturns whether this Attribute is equal to the specified HObject by comparing various properties.
- 
hashCode
- 
toStringReturns a string representation of the data value of the attribute. For example, "0, 255".For a compound datatype, it will be a 1D array of strings with field members separated by the delimiter. For example, "{0, 10.5}, {255, 20.0}, {512, 30.0}" is a compound attribute of {int, float} of three data points. - Parameters:
- delimiter- The delimiter used to separate individual data points. It can be a comma, semicolon, tab or space. For example, toString(",") will separate data by commas.
- Returns:
- the string representation of the data values.
 
- 
toStringReturns a string representation of the data value of the attribute. For example, "0, 255".For a compound datatype, it will be a 1D array of strings with field members separated by the delimiter. For example, "{0, 10.5}, {255, 20.0}, {512, 30.0}" is a compound attribute of {int, float} of three data points. - Parameters:
- delimiter- The delimiter used to separate individual data points. It can be a comma, semicolon, tab or space. For example, toString(",") will separate data by commas.
- maxItems- The maximum number of Array values to return
- Returns:
- the string representation of the data values.
 
- 
convertCompoundByteMemberGiven an array of bytes representing a compound Datatype and a start index and length, converts len number of bytes into the correct Object type and returns it.- Parameters:
- data- The byte array representing the data of the compound Datatype
- data_type- The type of data to convert the bytes to
- start- The start index of the bytes to get
- len- The number of bytes to convert
- Returns:
- The converted type of the bytes
 
 
-