Top Description Fields Constructors Methods
org.apache.poi.hpsf

public Class Section

extends Object
Class Inheritance
Imports
java.io.IOException, .OutputStream, .UnsupportedEncodingException, java.util.Arrays, .Date, .HashMap, .HashSet, .LinkedHashMap, .Map, .Set, .TreeMap, org.apache.commons.collections4.bidimap.TreeBidiMap, org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream, org.apache.logging.log4j.LogManager, .Logger, org.apache.poi.hpsf.wellknown.PropertyIDMap, org.apache.poi.util.CodePageUtil, .IOUtils, .LittleEndian, .LittleEndianByteArrayInputStream, .LittleEndianConsts, .LittleEndianOutputStream

Represents a section in a PropertySet.

Field Summary

Modifier and TypeField and Description
private final long
_offset

The offset of the section in the stream.

private Map<Long, String>
dictionary

Maps property IDs to section-private PID strings.

private ClassID
formatID

The section's format ID, getFormatID.

private static final Logger
private final Map<Long, Property>
properties

This section's properties.

private final UnsynchronizedByteArrayOutputStream
sectionBytes

Contains the bytes making out the section.

private transient boolean
wasNull

This member is true if the last call to getPropertyIntValue or getProperty tried to access a property that was not available, else false.

Constructor Summary

AccessConstructor and Description
public
Section()

Creates an empty Section.

public
Section(final Section
The section set to copy
s
)

Constructs a Section by doing a deep copy of an existing Section.

public
Section(final byte[]
Contains the complete property set stream.
src
,
final int
The position in the stream that points to the section's format ID.
offset
)

Creates a Section instance from a byte array.

Method Summary

Modifier and TypeMethod and Description
private int

Returns:

the section's length in bytes.
calcSize
()

Calculates the section's size.

public void
clear()

Removes all properties from the section including 0 (dictionary) and 1 (codepage).

public boolean

Returns:

true if the objects are equal, false if not
equals
(final Object
The object to compare this section with
o
)

Overrides java.lang.Object.equals.

Checks whether this section is equal to another object.

public int

Returns:

The section's codepage if one is defined, else -1.
getCodepage
()

Gets the section's codepage, if any.

public Map<Long, String>

Returns:

the dictionary or null if the section does not have a dictionary.
getDictionary
()

Gets the section's dictionary.

public ClassID

Returns:

The format ID
getFormatID
()

Returns the format ID. The format ID is the "type" of the section.

public long

Returns:

The offset of the section in the stream.
getOffset
()

Returns the offset of the section in the stream.

public String

Returns:

The well-known property ID string associated with the property ID pid
getPIDString
(final long
The property ID
pid
)

Returns the PID string associated with a property ID. The ID is first looked up in the Sections private dictionary.

public Property[]

Returns:

This section's properties.
getProperties
()

Returns this section's properties.

public Object

Returns:

The property's value
getProperty
(final long
The property's ID
id
)

Returns the value of the property with the specified ID. If the property is not available, null is returned and a subsequent call to wasNull will return true.

pack-priv boolean

Returns:

The property's value
getPropertyBooleanValue
(final int
The property's ID
id
)

Returns the value of the boolean property with the specified ID. If the property is not available, false is returned.

public int

Returns:

The number of properties in this section.
getPropertyCount
()

Returns the number of properties in this section.

pack-priv int

Returns:

The property's value
getPropertyIntValue
(final long
The property's ID
id
)

Returns the value of the numeric property with the specified ID. If the property is not available, 0 is returned.

public int

Returns:

the section's size in bytes.
getSize
()

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

private void
private static int

Returns:

the length of the current property
propLen
(TreeBidiMap<Long, Long>
the offset to id map
offset2Id
,
Long
the current entry key
entryOffset
,
long
the maximum offset/size of the section stream
maxSize
)

Retrieves the length of the given property (by key)

private boolean

Returns:

true if dictionary was read successful, false otherwise
readDictionary
(LittleEndianByteArrayInputStream
The byte stream containing the bytes making out the dictionary.
leis
,
final int
The dictionary contains at most this many bytes.
length
,
final int
The codepage of the string values.
codepage
)

Reads a dictionary.

public void
removeProperty(final long
The ID of the property to be removed
id
)

Removes a property.

public void
setCodepage(final int
the codepage
codepage
)

Sets the codepage.

public void
setDictionary(final Map<Long, String>
The dictionary
dictionary
)

Sets the section's dictionary.

public void
setFormatID(final ClassID
The section's format ID
formatID
)

Sets the section's format ID.

public void
setFormatID(final byte[]
The section's format ID as a byte array. It components are in big-endian format.
formatID
)

Sets the section's format ID.

public void
setProperties(final Property[]
This section's new properties.
properties
)

Sets this section's properties.

public void
setProperty(final int
The property's ID
id
,
final String
The property's value.
value
)

Sets the string value of the property with the specified ID.

public void
setProperty(final int
The property's ID
id
,
final int
The property's value.
value
)

Sets the int value of the property with the specified ID.

public void
setProperty(final int
The property's ID
id
,
final long
The property's value.
value
)

Sets the long value of the property with the specified ID.

public void
setProperty(final int
The property's ID
id
,
final boolean
The property's value.
value
)

Sets the boolean value of the property with the specified ID.

public void
setProperty(final int
The property's ID.
id
,
final long
The property's variant type.
variantType
,
final Object
The property's value.
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.

public void
setProperty(final Property
The property to be set.
p
)

Sets a property.

public void
setProperty(final int
The property ID.
id
,
final Object
The property's value. The value's class must be one of those supported by HPSF.
value
)

Sets a property.

protected void
setPropertyBooleanValue(final int
The property's ID
id
,
final boolean
The property's value
value
)

Sets the value of the boolean property with the specified ID.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public String
public boolean

Returns:

true if the last call to getPropertyIntValue or getProperty tried to access a property that was not available, else false.
wasNull
()

Checks whether the property which the last call to getPropertyIntValue or getProperty tried to access was available or not.

public int

Returns:

The number of bytes written, i.e. the section's size.
write
(final OutputStream
The stream to write into.
out
)

Writes this section into an output stream.

private void
writeDictionary(final OutputStream
The output stream to write to.
out
,
final int
The codepage to be used to write the dictionary items.
codepage
)

Writes the section's dictionary.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

_offsetback to summary
private final long _offset

The offset of the section in the stream.

dictionaryback to summary
private Map<Long, String> dictionary

Maps property IDs to section-private PID strings. These strings can be found in the property with ID 0.

formatIDback to summary
private ClassID formatID

The section's format ID, getFormatID.

LOGback to summary
private static final Logger LOG
propertiesback to summary
private final Map<Long, Property> properties

This section's properties.

sectionBytesback to summary
private final UnsynchronizedByteArrayOutputStream 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. If the array is empty, the section was modified and the bytes need to be regenerated.

wasNullback to summary
private transient boolean wasNull

This member is true if the last call to getPropertyIntValue or getProperty tried to access a property that was not available, else false.

Constructor Detail

Sectionback to summary
public Section()

Creates an empty Section.

Sectionback to summary
public Section(final Section s)

Constructs a Section by doing a deep copy of an existing Section. All nested Property instances, will be their mutable counterparts in the new MutableSection.

Parameters
s:Section

The section set to copy

Sectionback to summary
public Section(final byte[] src, final int offset) throws UnsupportedEncodingException

Creates a Section instance from a byte array.

Parameters
src:byte[]

Contains the complete property set stream.

offset:int

The position in the stream that points to the section's format ID.

Exceptions
UnsupportedEncodingException:
if the section's codepage is not supported.

Method Detail

calcSizeback to summary
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.

Returns:int

the section's length in bytes.

Exceptions
WritingNotSupportedException:
If the document is opened read-only.
IOException:
If an error happens while writing.
clearback to summary
public void clear()

Removes all properties from the section including 0 (dictionary) and 1 (codepage).

equalsback to summary
public boolean equals(final Object o)

Overrides java.lang.Object.equals.

Checks whether this section is equal to another object. The result is false if one of the following conditions holds:

  • The other object is not a Section.
  • The format IDs of the two sections are not equal.
  • The sections have a different number of properties. However, properties with ID 1 (codepage) are not counted.
  • The other object is not a Section.
  • The properties have different values. The order of the properties is irrelevant.
Parameters
o:Object

The object to compare this section with

Returns:boolean

true if the objects are equal, false if not

Annotations
@Override
getCodepageback to summary
public int getCodepage()

Gets the section's codepage, if any.

Returns:int

The section's codepage if one is defined, else -1.

getDictionaryback to summary
public Map<Long, String> getDictionary()

Gets the section's dictionary. A dictionary allows an application to use human-readable property names instead of numeric property IDs. It contains mappings from property IDs to their associated string values. The dictionary is stored as the property with ID 0. The codepage for the strings in the dictionary is defined by property with ID 1.

Returns:Map<Long, String>

the dictionary or null if the section does not have a dictionary.

Annotations
@SuppressWarnings:unchecked
getFormatIDback to summary
public ClassID getFormatID()

Returns the format ID. The format ID is the "type" of the section. For example, if the format ID of the first Section contains the bytes specified by org.apache.poi.hpsf.wellknown.SectionIDMap.SUMMARY_INFORMATION_ID the section (and thus the property set) is a SummaryInformation.

Returns:ClassID

The format ID

getOffsetback to summary
public long getOffset()

Returns the offset of the section in the stream.

Returns:long

The offset of the section in the stream.

getPIDStringback to summary
public String getPIDString(final long pid)

Returns the PID string associated with a property ID. The ID is first looked up in the Sections private dictionary. If it is not found there, the property PID string is taken from sections format IDs namespace. If the PID is also undefined there, i.e. it is not well-known, "[undefined]" is returned.

Parameters
pid:long

The property ID

Returns:String

The well-known property ID string associated with the property ID pid

getPropertiesback to summary
public Property[] getProperties()

Returns this section's properties.

Returns:Property[]

This section's properties.

getPropertyback to summary
public Object getProperty(final long id)

Returns the value of the property with the specified ID. If the property is not available, null is returned and a subsequent call to wasNull will return true.

Parameters
id:long

The property's ID

Returns:Object

The property's value

getPropertyBooleanValueback to summary
pack-priv boolean getPropertyBooleanValue(final int id)

Returns the value of the boolean property with the specified ID. If the property is not available, false is returned. A subsequent call to wasNull will return true to let the caller distinguish that case from a real property value of false.

Parameters
id:int

The property's ID

Returns:boolean

The property's value

getPropertyCountback to summary
public int getPropertyCount()

Returns the number of properties in this section.

Returns:int

The number of properties in this section.

getPropertyIntValueback to summary
pack-priv int getPropertyIntValue(final long id)

Returns the value of the numeric property with the specified ID. If the property is not available, 0 is returned. A subsequent call to wasNull will return true to let the caller distinguish that case from a real property value of 0.

Parameters
id:long

The property's ID

Returns:int

The property's value

getSizeback to summary
public int getSize()
Returns:int

the section's size in bytes.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
padSectionBytesback to summary
private void padSectionBytes()
propLenback to summary
private static int propLen(TreeBidiMap<Long, Long> offset2Id, Long entryOffset, long maxSize)

Retrieves the length of the given property (by key)

Parameters
offset2Id:TreeBidiMap<Long, Long>

the offset to id map

entryOffset:Long

the current entry key

maxSize:long

the maximum offset/size of the section stream

Returns:int

the length of the current property

readDictionaryback to summary
private boolean readDictionary(LittleEndianByteArrayInputStream leis, final int length, final int codepage)

Reads a dictionary.

Parameters
leis:LittleEndianByteArrayInputStream

The byte stream containing the bytes making out the dictionary.

length:int

The dictionary contains at most this many bytes.

codepage:int

The codepage of the string values.

Returns:boolean

true if dictionary was read successful, false otherwise

removePropertyback to summary
public void removeProperty(final long id)

Removes a property.

Parameters
id:long

The ID of the property to be removed

Annotations
@SuppressWarnings:WeakerAccess
setCodepageback to summary
public void setCodepage(final int codepage)

Sets the codepage.

Parameters
codepage:int

the codepage

setDictionaryback to summary
public void setDictionary(final Map<Long, String> dictionary) throws IllegalPropertySetDataException

Sets the section's dictionary. All keys in the dictionary must be Long instances, all values must be Strings. 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.

Parameters
dictionary:Map<Long, String>

The dictionary

Exceptions
IllegalPropertySetDataException:
if the dictionary's key and value types are not correct.
See Also
Section#getDictionary()
setFormatIDback to summary
public void setFormatID(final ClassID formatID)

Sets the section's format ID.

Parameters
formatID:ClassID

The section's format ID

setFormatIDback to summary
public void setFormatID(final byte[] formatID)

Sets the section's format ID.

Parameters
formatID:byte[]

The section's format ID as a byte array. It components are in big-endian format.

Annotations
@SuppressWarnings:WeakerAccess
setPropertiesback to summary
public void setProperties(final Property[] properties)

Sets this section's properties. Any former values are overwritten.

Parameters
properties:Property[]

This section's new properties.

setPropertyback to summary
public void setProperty(final int id, final String value)

Sets the string value of the property with the specified ID.

Parameters
id:int

The property's ID

value:String

The property's value.

setPropertyback to summary
public void setProperty(final int id, final int value)

Sets the int value of the property with the specified ID.

Parameters
id:int

The property's ID

value:int

The property's value.

See Also
setProperty(int, long, Object), getProperty
setPropertyback to summary
public void setProperty(final int id, final long value)

Sets the long value of the property with the specified ID.

Parameters
id:int

The property's ID

value:long

The property's value.

See Also
setProperty(int, long, Object), getProperty
setPropertyback to summary
public void setProperty(final int id, final boolean value)

Sets the boolean value of the property with the specified ID.

Parameters
id:int

The property's ID

value:boolean

The property's value.

See Also
setProperty(int, long, Object), getProperty
setPropertyback to summary
public void setProperty(final int id, final long variantType, final 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.

Parameters
id:int

The property's ID.

variantType:long

The property's variant type.

value:Object

The property's value.

See Also
setProperty(int, String), getProperty, Variant
setPropertyback to summary
public void setProperty(final Property p)

Sets a property.

Parameters
p:Property

The property to be set.

See Also
setProperty(int, long, Object), getProperty, Variant
setPropertyback to summary
public void setProperty(final int id, final Object value)

Sets a property.

Parameters
id:int

The property ID.

value:Object

The property's value. The value's class must be one of those supported by HPSF.

setPropertyBooleanValueback to summary
protected void setPropertyBooleanValue(final int id, final boolean value)

Sets the value of the boolean property with the specified ID.

Parameters
id:int

The property's ID

value:boolean

The property's value

Annotations
@SuppressWarnings:unused
See Also
setProperty(int, long, Object), getProperty, Variant
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
toStringback to summary
public String toString(PropertyIDMap idMap)
wasNullback to summary
public boolean wasNull()

Checks whether the property which the last call to getPropertyIntValue or getProperty tried to access was available or not. This information might be important for callers of getPropertyIntValue since the latter returns 0 if the property does not exist. Using wasNull the caller can distiguish this case from a property's real value of 0.

Returns:boolean

true if the last call to getPropertyIntValue or getProperty tried to access a property that was not available, else false.

Annotations
@SuppressWarnings:WeakerAccess
writeback to summary
public int write(final 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.

Parameters
out:OutputStream

The stream to write into.

Returns:int

The number of bytes written, i.e. the section's size.

Exceptions
WritingNotSupportedException:
if HPSF does not yet support writing a property's variant type.
IOException:
if an I/O error occurs
writeDictionaryback to summary
private void writeDictionary(final OutputStream out, final int codepage) throws IOException

Writes the section's dictionary.

Parameters
out:OutputStream

The output stream to write to.

codepage:int

The codepage to be used to write the dictionary items.

Exceptions
IOException:
if an I/O exception occurs.