Methods Summary |
---|
public void | addSection(org.apache.poi.hpsf.Section section)Adds a section to this property set.
if (sections == null)
sections = new LinkedList();
sections.add(section);
|
public void | clearSections()Removes all sections from this property set.
sections = null;
|
public void | setByteOrder(int byteOrder)Sets the "byteOrder" property. /* Section count */
this.byteOrder = byteOrder;
|
public void | setClassID(org.apache.poi.hpsf.ClassID classID)Sets the property set stream's low-level "class ID"
field.
this.classID = classID;
|
public void | setFormat(int format)Sets the "format" property.
this.format = format;
|
public void | setOSVersion(int osVersion)Sets the "osVersion" property.
this.osVersion = osVersion;
|
public java.io.InputStream | toInputStream()Returns the contents of this property set stream as an input stream.
The latter can be used for example to write the property set into a POIFS
document. The input stream represents a snapshot of the property set.
If the latter is modified while the input stream is still being
read, the modifications will not be reflected in the input stream but in
the {@link MutablePropertySet} only.
final ByteArrayOutputStream psStream = new ByteArrayOutputStream();
write(psStream);
psStream.close();
final byte[] streamData = psStream.toByteArray();
return new ByteArrayInputStream(streamData);
|
public void | write(org.apache.poi.poifs.filesystem.DirectoryEntry dir, java.lang.String name)Writes a property set to a document in a POI filesystem directory.
/* If there is already an entry with the same name, remove it. */
try
{
final Entry e = dir.getEntry(name);
e.delete();
}
catch (FileNotFoundException ex)
{
/* Entry not found, no need to remove it. */
}
/* Create the new entry. */
dir.createDocument(name, toInputStream());
|
public void | write(java.io.OutputStream out)Writes the property set to an output stream.
/* Write the number of sections in this property set stream. */
final int nrSections = sections.size();
int length = 0;
/* Write the property set's header. */
length += TypeWriter.writeToStream(out, (short) getByteOrder());
length += TypeWriter.writeToStream(out, (short) getFormat());
length += TypeWriter.writeToStream(out, getOSVersion());
length += TypeWriter.writeToStream(out, getClassID());
length += TypeWriter.writeToStream(out, nrSections);
int offset = OFFSET_HEADER;
/* Write the section list, i.e. the references to the sections. Each
* entry in the section list consist of the section's class ID and the
* section's offset relative to the beginning of the stream. */
offset += nrSections * (ClassID.LENGTH + LittleEndian.INT_SIZE);
final int sectionsBegin = offset;
for (final ListIterator i = sections.listIterator(); i.hasNext();)
{
final MutableSection s = (MutableSection) i.next();
final ClassID formatID = s.getFormatID();
if (formatID == null)
throw new NoFormatIDException();
length += TypeWriter.writeToStream(out, s.getFormatID());
length += TypeWriter.writeUIntToStream(out, offset);
try
{
offset += s.getSize();
}
catch (HPSFRuntimeException ex)
{
final Throwable cause = ex.getReason();
if (cause instanceof UnsupportedEncodingException)
throw new IllegalPropertySetDataException(cause);
else
throw ex;
}
}
/* Write the sections themselves. */
offset = sectionsBegin;
for (final ListIterator i = sections.listIterator(); i.hasNext();)
{
final MutableSection s = (MutableSection) i.next();
offset += s.write(out);
}
|