FileDocCategorySizeDatePackage
SprmBuffer.javaAPI DocApache Poi 3.0.14727Mon Jan 01 18:55:34 GMT 2007org.apache.poi.hwpf.sprm

SprmBuffer

public class SprmBuffer extends Object implements Cloneable

Fields Summary
byte[]
_buf
int
_offset
boolean
_istd
Constructors Summary
public SprmBuffer(byte[] buf, boolean istd)

    _offset = buf.length;
    _buf = buf;
    _istd = istd;
  
public SprmBuffer(byte[] buf)

    this(buf, false);
  
public SprmBuffer()

    _buf = new byte[4];
    _offset = 0;
  
Methods Summary
public voidaddSprm(short opcode, int operand)

    int addition = LittleEndian.SHORT_SIZE + LittleEndian.INT_SIZE;
    ensureCapacity(addition);
    LittleEndian.putShort(_buf, _offset, opcode);
    _offset += LittleEndian.SHORT_SIZE;
    LittleEndian.putInt(_buf, _offset, operand);
    _offset += LittleEndian.INT_SIZE;
  
public voidaddSprm(short opcode, byte[] operand)

    int addition = LittleEndian.SHORT_SIZE + LittleEndian.BYTE_SIZE + operand.length;
    ensureCapacity(addition);
    LittleEndian.putShort(_buf, _offset, opcode);
    _offset += LittleEndian.SHORT_SIZE;
    _buf[_offset++] = (byte)operand.length;
    System.arraycopy(operand, 0, _buf, _offset, operand.length);
  
public voidaddSprm(short opcode, byte operand)

    int addition = LittleEndian.SHORT_SIZE + LittleEndian.BYTE_SIZE;
    ensureCapacity(addition);
    LittleEndian.putShort(_buf, _offset, opcode);
    _offset += LittleEndian.SHORT_SIZE;
    _buf[_offset++] = operand;
  
public voidaddSprm(short opcode, short operand)

    int addition = LittleEndian.SHORT_SIZE + LittleEndian.SHORT_SIZE;
    ensureCapacity(addition);
    LittleEndian.putShort(_buf, _offset, opcode);
    _offset += LittleEndian.SHORT_SIZE;
    LittleEndian.putShort(_buf, _offset, operand);
    _offset += LittleEndian.SHORT_SIZE;
  
public voidappend(byte[] grpprl)

    ensureCapacity(grpprl.length);
    System.arraycopy(grpprl, 0, _buf, _offset, grpprl.length);
  
public java.lang.Objectclone()

    SprmBuffer retVal = (SprmBuffer)super.clone();
    retVal._buf = new byte[_buf.length];
    System.arraycopy(_buf, 0, retVal._buf, 0, _buf.length);
    return retVal;
  
private voidensureCapacity(int addition)

    if (_offset + addition >= _buf.length)
    {
      // add 6 more than they need for use the next iteration
      byte[] newBuf = new byte[_offset + addition + 6];
      System.arraycopy(_buf, 0, newBuf, 0, _buf.length);
      _buf = newBuf;
    }
  
public booleanequals(java.lang.Object obj)

    SprmBuffer sprmBuf = (SprmBuffer)obj;
    return (Arrays.equals(_buf, sprmBuf._buf));
  
private intfindSprm(short opcode)

    int operation = SprmOperation.getOperationFromOpcode(opcode);
    int type = SprmOperation.getTypeFromOpcode(opcode);

    SprmIterator si = new SprmIterator(_buf, 2);
    while(si.hasNext())
    {
      SprmOperation i = si.next();
      if(i.getOperation() == operation && i.getType() == type)
        return i.getGrpprlOffset();
    }
    return -1;
  
public byte[]toByteArray()

    return _buf;
  
public voidupdateSprm(short opcode, byte operand)

    int grpprlOffset = findSprm(opcode);
    if(grpprlOffset != -1)
    {
      _buf[grpprlOffset] = operand;
      return;
    }
    else addSprm(opcode, operand);
  
public voidupdateSprm(short opcode, short operand)

    int grpprlOffset = findSprm(opcode);
    if(grpprlOffset != -1)
    {
      LittleEndian.putShort(_buf, grpprlOffset, operand);
      return;
    }
    else addSprm(opcode, operand);
  
public voidupdateSprm(short opcode, int operand)

    int grpprlOffset = findSprm(opcode);
    if(grpprlOffset != -1)
    {
      LittleEndian.putInt(_buf, grpprlOffset, operand);
      return;
    }
    else addSprm(opcode, operand);