public class MutableSection extends Section
Adds writing capability to the Section
class.
Please be aware that this class' functionality will be merged into the
Section
class at a later time, so the API will change.
Section.PropertyListEntry
Modifier and Type | Field and Description |
---|---|
private boolean |
dirty
If the "dirty" flag is true, the section's size must be
(re-)calculated before the section is written.
|
private List |
preprops
List to assemble the properties.
|
private byte[] |
sectionBytes
Contains the bytes making out the section.
|
dictionary, formatID, offset, properties, size
Constructor and Description |
---|
MutableSection()
Creates an empty mutable section.
|
MutableSection(Section s)
Constructs a
MutableSection by doing a deep copy of an
existing Section . |
Modifier and Type | Method and Description |
---|---|
private int |
calcSize()
Calculates the section's size.
|
void |
clear()
Removes all properties from the section including 0 (dictionary) and
1 (codepage).
|
Property[] |
getProperties()
Gets this section's properties.
|
Object |
getProperty(long id)
Gets a property.
|
int |
getPropertyCount()
Overwrites the super class' method to cope with a redundancy:
the property count is maintained in a separate member variable, but
shouldn't.
|
int |
getSize()
Returns the section's size.
|
void |
removeProperty(long id)
Removes a property.
|
void |
setCodepage(int codepage)
Sets the codepage.
|
void |
setDictionary(Map dictionary)
Sets the section's dictionary.
|
void |
setFormatID(byte[] formatID)
Sets the section's format ID.
|
void |
setFormatID(ClassID formatID)
Sets the section's format ID.
|
void |
setProperties(Property[] properties)
Sets this section's properties.
|
void |
setProperty(int id,
boolean value)
Sets the boolean value of the property with the specified ID.
|
void |
setProperty(int id,
int value)
Sets the int value of the property with the specified ID.
|
void |
setProperty(int id,
long value)
Sets the long value of the property with the specified ID.
|
void |
setProperty(int id,
long variantType,
Object value)
Sets the value and the variant type of the property with the
specified ID.
|
void |
setProperty(int id,
Object value)
Sets a property.
|
void |
setProperty(int id,
String value)
Sets the string value of the property with the specified ID.
|
void |
setProperty(Property p)
Sets a property.
|
protected void |
setPropertyBooleanValue(int id,
boolean value)
Sets the value of the boolean property with the specified
ID.
|
int |
write(OutputStream out)
Writes this section into an output stream.
|
private static int |
writeDictionary(OutputStream out,
Map dictionary,
int codepage)
Writes the section's dictionary.
|
equals, getCodepage, getDictionary, getFormatID, getOffset, getPIDString, getPropertyBooleanValue, getPropertyIntValue, hashCode, toString, wasNull
private boolean dirty
If the "dirty" flag is true, the section's size must be (re-)calculated before the section is written.
private List preprops
List to assemble the properties. Unfortunately a wrong
decision has been taken when specifying the "properties" field
as an Property[]. It should have been a List
.
private byte[] sectionBytes
Contains the bytes making out the section. This byte array is established when the section's size is calculated and can be reused later. It is valid only if the "dirty" flag is false.
public MutableSection()
Creates an empty mutable section.
public MutableSection(Section s)
Constructs a MutableSection
by doing a deep copy of an
existing Section
. All nested Property
instances, will be their mutable counterparts in the new
MutableSection
.
s
- The section set to copypublic void setFormatID(ClassID formatID)
Sets the section's format ID.
formatID
- The section's format IDsetFormatID(byte[])
,
Section.getFormatID()
public void setFormatID(byte[] formatID)
Sets the section's format ID.
formatID
- The section's format ID as a byte array. It components
are in big-endian format.setFormatID(ClassID)
,
Section.getFormatID()
public void setProperties(Property[] properties)
Sets this section's properties. Any former values are overwritten.
properties
- This section's new properties.public void setProperty(int id, String value)
Sets the string value of the property with the specified ID.
id
- The property's IDvalue
- The property's value. It will be written as a Unicode
string.setProperty(int, long, Object)
,
getProperty(long)
public void setProperty(int id, int value)
Sets the int value of the property with the specified ID.
id
- The property's IDvalue
- The property's value.setProperty(int, long, Object)
,
getProperty(long)
public void setProperty(int id, long value)
Sets the long value of the property with the specified ID.
id
- The property's IDvalue
- The property's value.setProperty(int, long, Object)
,
getProperty(long)
public void setProperty(int id, boolean value)
Sets the boolean value of the property with the specified ID.
id
- The property's IDvalue
- The property's value.setProperty(int, long, Object)
,
getProperty(long)
public void setProperty(int id, long variantType, Object value)
Sets the value and the variant type of the property with the specified ID. If a property with this ID is not yet present in the section, it will be added. An already present property with the specified ID will be overwritten. A default mapping will be used to choose the property's type.
id
- The property's ID.variantType
- The property's variant type.value
- The property's value.setProperty(int, String)
,
getProperty(long)
,
Variant
public void setProperty(Property p)
Sets a property.
p
- The property to be set.setProperty(int, long, Object)
,
getProperty(long)
,
Variant
public void removeProperty(long id)
Removes a property.
id
- The ID of the property to be removedprotected void setPropertyBooleanValue(int id, boolean value)
Sets the value of the boolean property with the specified ID.
id
- The property's IDvalue
- The property's valuesetProperty(int, long, Object)
,
getProperty(long)
,
Variant
public int getSize()
Returns the section's size.
private int calcSize() throws WritingNotSupportedException, IOException
Calculates the section's size. It is the sum of the lengths of the section's header (8), the properties list (16 times the number of properties) and the properties themselves.
WritingNotSupportedException
IOException
public int write(OutputStream out) throws WritingNotSupportedException, IOException
Writes this section into an output stream.
Internally this is done by writing into three byte array output streams: one for the properties, one for the property list and one for the section as such. The two former are appended to the latter when they have received all their data.
out
- The stream to write into.IOException
- if an I/O error occursWritingNotSupportedException
- if HPSF does not yet support
writing a property's variant type.private static int writeDictionary(OutputStream out, Map dictionary, int codepage) throws IOException
Writes the section's dictionary.
out
- The output stream to write to.dictionary
- The dictionary.codepage
- The codepage to be used to write the dictionary items.IOException
- if an I/O exception occurs.public int getPropertyCount()
Overwrites the super class' method to cope with a redundancy: the property count is maintained in a separate member variable, but shouldn't.
getPropertyCount
in class Section
public Property[] getProperties()
Gets this section's properties.
getProperties
in class Section
public Object getProperty(long id)
Gets a property.
getProperty
in class Section
id
- The ID of the property to getnull
if there is no such propertypublic void setDictionary(Map dictionary) throws IllegalPropertySetDataException
Sets the section's dictionary. All keys in the dictionary must be
Long
instances, all values must be
String
s. This method overwrites the properties with IDs
0 and 1 since they are reserved for the dictionary and the dictionary's
codepage. Setting these properties explicitly might have surprising
effects. An application should never do this but always use this
method.
dictionary
- The dictionaryIllegalPropertySetDataException
- if the dictionary's key and
value types are not correct.Section.getDictionary()
public void setProperty(int id, Object value)
Sets a property.
id
- The property ID.value
- The property's value. The value's class must be one of those
supported by HPSF.public void clear()
Removes all properties from the section including 0 (dictionary) and 1 (codepage).
public void setCodepage(int codepage)
Sets the codepage.
codepage
- the codepageCopyright © 2016 Open Microscopy Environment