PlexOfCpspublic class PlexOfCps extends Object common data structure in a Word file. Contains an array of 4 byte ints in
the front that relate to an array of abitrary data structures in the back. |
Fields Summary |
---|
private int | _count | private int | _offset | private int | _sizeOfStruct | private ArrayList | _props |
Constructors Summary |
---|
public PlexOfCps(int sizeOfStruct)
_props = new ArrayList();
_sizeOfStruct = sizeOfStruct;
| public PlexOfCps(byte[] buf, int start, int size, int sizeOfStruct)Constructor
_count = (size - 4)/(4 + sizeOfStruct);
_sizeOfStruct = sizeOfStruct;
_props = new ArrayList(_count);
for (int x = 0; x < _count; x++)
{
_props.add(getProperty(x, buf, start));
}
|
Methods Summary |
---|
public void | addProperty(org.apache.poi.hwpf.model.GenericPropertyNode node)
_props.add(node);
| private int | getIntOffset(int index)
return index * 4;
| public org.apache.poi.hwpf.model.GenericPropertyNode | getProperty(int index)
return (GenericPropertyNode)_props.get(index);
| private org.apache.poi.hwpf.model.GenericPropertyNode | getProperty(int index, byte[] buf, int offset)
int start = LittleEndian.getInt(buf, offset + getIntOffset(index));
int end = LittleEndian.getInt(buf, offset + getIntOffset(index+1));
byte[] struct = new byte[_sizeOfStruct];
System.arraycopy(buf, offset + getStructOffset(index), struct, 0, _sizeOfStruct);
return new GenericPropertyNode(start, end, struct);
| private int | getStructOffset(int index)Returns the offset, in bytes, from the beginning if this PlexOfCps to
the data structure at index.
return (4 * (_count + 1)) + (_sizeOfStruct * index);
| public int | length()returns the number of data structures in this PlexOfCps.
return _count;
| public byte[] | toByteArray()
int size = _props.size();
int cpBufSize = ((size + 1) * LittleEndian.INT_SIZE);
int structBufSize = + (_sizeOfStruct * size);
int bufSize = cpBufSize + structBufSize;
byte[] buf = new byte[bufSize];
GenericPropertyNode node = null;
for (int x = 0; x < size; x++)
{
node = (GenericPropertyNode)_props.get(x);
// put the starting offset of the property into the plcf.
LittleEndian.putInt(buf, (LittleEndian.INT_SIZE * x), node.getStart());
// put the struct into the plcf
System.arraycopy(node.getBytes(), 0, buf, cpBufSize + (x * _sizeOfStruct),
_sizeOfStruct);
}
// put the ending offset of the last property into the plcf.
LittleEndian.putInt(buf, LittleEndian.INT_SIZE * size, node.getEnd());
return buf;
|
|