FileDocCategorySizeDatePackage
PlexOfCps.javaAPI DocApache Poi 3.0.14094Mon Jan 01 18:55:32 GMT 2007org.apache.poi.hwpf.model

PlexOfCps

public 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.
author
Ryan Ackley

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

param
size The size in bytes of this PlexOfCps
param
sizeOfStruct The size of the data structure type stored in this PlexOfCps.

    _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 voidaddProperty(org.apache.poi.hwpf.model.GenericPropertyNode node)

    _props.add(node);
  
private intgetIntOffset(int index)

    return index * 4;
  
public org.apache.poi.hwpf.model.GenericPropertyNodegetProperty(int index)

    return (GenericPropertyNode)_props.get(index);
  
private org.apache.poi.hwpf.model.GenericPropertyNodegetProperty(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 intgetStructOffset(int index)
Returns the offset, in bytes, from the beginning if this PlexOfCps to the data structure at index.

param
index The index of the data structure.
return
The offset, in bytes, from the beginning if this PlexOfCps to the data structure at index.

    return (4 * (_count + 1)) + (_sizeOfStruct * index);
  
public intlength()
returns the number of data structures in this PlexOfCps.

return
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;