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

TextPiece

public class TextPiece extends PropertyNode implements Comparable
Lightweight representation of a text piece.
author
Ryan Ackley

Fields Summary
private boolean
_usesUnicode
private PieceDescriptor
_pd
private int
_cpStart
Constructors Summary
public TextPiece(int start, int end, byte[] text, PieceDescriptor pd, int cpStart)

param
start Offset in main document stream.

     /** start - end is length on file. This is double the expected when its
     * unicode.*/
    super(start, end, new StringBuffer(new String(text, pd.isUnicode() ? "UTF-16LE" : "Cp1252")));
    _usesUnicode = pd.isUnicode();
    _pd = pd;
    _cpStart = cpStart;
  
Methods Summary
public voidadjustForDelete(int start, int length)


   
public intcharacterLength()

     return (getEnd() - getStart()) / (_usesUnicode ? 2 : 1);
   
public booleanequals(java.lang.Object o)

     if (limitsAreEqual(o))
     {
       TextPiece tp = (TextPiece)o;
       return getStringBuffer().toString().equals(tp.getStringBuffer().toString()) &&
              tp._usesUnicode == _usesUnicode && _pd.equals(tp._pd);
     }
     return false;
   
public intgetCP()

     return _cpStart;
   
public org.apache.poi.hwpf.model.PieceDescriptorgetPieceDescriptor()

     return _pd;
   
public byte[]getRawBytes()

     try
     {
       return ((StringBuffer)_buf).toString().getBytes(_usesUnicode ?
           "UTF-16LE" : "Cp1252");
     }
     catch (UnsupportedEncodingException ignore)
     {
       // shouldn't ever happen considering we wouldn't have been able to
       // create the StringBuffer w/o getting this exception
       return ((StringBuffer)_buf).toString().getBytes();
     }

   
public java.lang.StringBuffergetStringBuffer()

     return (StringBuffer)_buf;
   
public java.lang.Stringsubstring(int start, int end)

     int denominator = _usesUnicode ? 2 : 1;

     return ((StringBuffer)_buf).substring(start/denominator, end/denominator);
   
public booleanusesUnicode()

return
If this text piece uses unicode

      return _usesUnicode;